在C中将Char转换为String [英] Convert Char to String in C
本文介绍了在C中将Char转换为String的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在C语言中将字符转换为字符串。我目前正在使用 c = fgetc(fp)
返回一个字符。但是我需要在strcpy中使用一个字符串
How do I convert a character to a string in C. I'm currently using c = fgetc(fp)
which returns a character. But I need a string to be used in strcpy
推荐答案
要回答这个问题,而又不会读太多其他内容
To answer the question without reading too much else into it i would
char str[2] = "\0"; /* gives {\0, \0} */
str[0] = fgetc(fp);
您可以在循环中使用第二行以及您想继续使用char的其他字符串操作作为字符串。
You could use the second line in a loop with what ever other string operations you want to keep using char's as strings.
这篇关于在C中将Char转换为String的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文