在 C 中将字符转换为字符串 [英] Convert Char to String in C

查看:21
本文介绍了在 C 中将字符转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 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] = ""; /* gives {, } */
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 中将字符转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆