将int n转换为c中长n的字符串
地狱,我是C的新手,想了解字符串和整数转换。
我正在尝试编写一个函数,该函数采用整数n,转换为由n长n组成的字符串。然后根据字母的n数字将其转换回一个字符串。
例如,如果我输入INT 3,它将返回由3个长度3的字符串,因此“ 333”。然后,我想将其转换为“ CCC”,因为它是字母的第三个字母。
另一个示例是函数在整数5中的功能,然后返回“ eeeee”。 第5个字母的5个字母
到目前为止,
int *num = 3;
char* buffer[sizeof(int) * 4 + 1]; //got this from another question
sprintf(buffer, "%d", key_num) //turn int into char
这是我的代码:将不胜感激
Hell I am very new to C and wanted to learn about strings and integer conversion.
I am trying to write a function that takes an integer n, converts to a string consisting of n's of length n. And then convert that back to a string based on the nth number of the alphabet.
For example, if i enter in int 3, it will return a string of length 3, consisting of 3, so "333". And then I would like to convert this into "CCC" since it is the 3rd letter of the alphabet.
Another example would be the function takes in the integer 5, and returns "EEEEE". 5 letters of the 5th letter of the alphabet
So far this is my code:
int *num = 3;
char* buffer[sizeof(int) * 4 + 1]; //got this from another question
sprintf(buffer, "%d", key_num) //turn int into char
Anyhelp would be appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您不熟悉 c (例如 c )的新手。通常,对于不使用复杂的语法和数据结构的任务,请尝试保持简单,C可以使您对类型的低水平控制,如果您将来可能需要进一步使用它,则需要掌握它。
If you are new to a low level programming language like C and you care about it then I strongly suggest you to go through a textbook and learn it from scratch rather than combining snipets of code. In general try to keep it simple and for tasks like that don't use complex syntax and data structures, c gives you low level control of types and that's something that you need to master if you perhaps need to use it further in the future.