Arrays 如何将整数值放入字符数组中?我希望数字1234在字符数组中。我不能从提示中读出来

Arrays 如何将整数值放入字符数组中?我希望数字1234在字符数组中。我不能从提示中读出来,arrays,char,int,Arrays,Char,Int,我是C语言的新手,在上两个程序之前,我的在线课程都做得很好。他们变得越来越复杂,而我也不是什么战略家。但是,我正在努力,我很沮丧 我已经做了一段时间了,它已经过期了,我的ulimate目标是把一个数字转换成单词作为薪水 我在这里要做的是将双精度值转换为int,并将int放入一个char数组,这样,如果pay是$1234.56 001234,那么最终数组金额将被读取。然后我想我可以为每个位置做ifs或CASE,hundThous=0,tenThous=0,Thous=1,等等。。转换它。但是我被困

我是C语言的新手,在上两个程序之前,我的在线课程都做得很好。他们变得越来越复杂,而我也不是什么战略家。但是,我正在努力,我很沮丧

我已经做了一段时间了,它已经过期了,我的ulimate目标是把一个数字转换成单词作为薪水

我在这里要做的是将双精度值转换为int,并将int放入一个char数组,这样,如果pay是$1234.56 001234,那么最终数组金额将被读取。然后我想我可以为每个位置做ifs或CASE,hundThous=0,tenThous=0,Thous=1,等等。。转换它。但是我被困在这里,需要帮助

如何将值1234放入char数组

另外,在上面的函数中,我调用了checkWritermoney,钱是双倍的。对吗?我只想让它调用这个函数,将转换后的双精度文本打印成单词

    void checkWriter(double z)
    {
       double v;
       int w, y, cents;
       int b, c, x, length;
       char array[SIZE];
       char amount[SIZE]; /*size = 7, our largest value will be in the hundred thousands*/

       v = 100 * z; /*make z a whole number*/

       w = ((int)v); /*convert z to an integer w*/

       cents = w % 100; /*cents equals the remainder of w/100*/

       y = (w - cents)/100; /*y equals the converted integer minus cents, divided by 100*/

       sprintf(array, "%-6d", y); /* ATTEMPTING TO PUT y INTO array (saw this on google) */
       printf("%s\n\n", array); /* Just wanted to see if it worked.  It didn't.  I got -2big
                                   number.*/

       length = strnlen(array); /*find length of the value in array*/

       array[length] = '\0'; /* affix terminating null character to array */

       b = SIZE - length - 1; /* b is amount of zeroes needed */

       for(c = 0; c < length - 1; c++) { /* loops, plugging zeroes in amount until b=c, 
                                            then attaches array to amount */
          if(b == c) {
             amount[c] = '\0';
             strcat(amount, array);
          }
          else {
             amount[c] = '0';
          }
       }

       printf("%s\n\n", amount); /* Checking to see if it worked. Nope.  All zeroes. And 
                                    sometimes extra symbols at the end*/

       return;
    }
非常感谢你的帮助。谢谢你

请看和文章。 基本上,您可以使用

(int)double_value;
然后使用

snprintf(arr, length, "%d", your_integer);