c - C 程序中的字符串

标签 c

我正在用 C 语言编写一个程序,它打印字符串/文本的 ASCII包括空格。该程序工作正常,并给出包含空格的字符串的精确 ASCII 值,但问题是它还在所有 ASCII 值的末尾打印“10”。

这是我的代码:

#include<stdio.h>
#include<conio.h>
int main()
    {
       char str[100];
       int i;
       printf("Enter a string: ");
       fgets(str,100,stdin); 
       //scanf("%s",str);
       printf("String is: %s\n",str);
       printf("ASCII value in Decimal is: ");
      for(i=0; str[i]!='\0'; i++)
        {
             printf("%d ",str[i]);
          }
          printf("\n");
    getch();
}                                             

请帮帮我,告诉我问题是什么以及如何解决。提前致谢。

最佳答案

当您使用 fgets 读取字符串时,您按下的输入将包含在字符串中 ( man page )。 \n 的 ASCII 代码为 10

关于c - C 程序中的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43853749/

相关文章:

c - 错误: Invalid argument while trying to accept a connection from a client

c - 为什么微软将类型CHAR定义为char,将宏CONST定义为const?

c - Windows 中有等效的 gcc 吗?

c - 如何解决 "Error: can' t打开elf64读取: No such file or directory"

c++ - 对 `DES_set_odd_parity' 的 undefined reference

python - Cython 扩展类型是否支持类属性?

c - ARGV中的 vector 是指一维数组吗?

C 宏 - 变量类型,它是如何工作的?

c - C语言中 int* pn = &n 和 int pn = &n 有什么区别

c - 用 C 从串口读取,ReadFile 可能有问题?