Lines in a C program

I am making a C program that prints the ASCII value of a string / text including spaces . The program works fine and gives the exact ASCII values โ€‹โ€‹of the string, including spaces, but the problem is that it also prints "10" at the end of all ASCII values.

This is my code:

#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();
}                                             

      

Please help me, tell me what the problem is and how to fix it. Thank you in advance.

+3


source to share


1 answer


When you read a line, the fgets

input when pressed is included in the line ( man page ). ASCII code for \n

- 10

.



0


source







All Articles