0

//it accepts input but skips first and last char of sentence anyone explan it clearly.

#include<stdio.h>
#include <stdlib.h>

int main()
{
    int i=0,j=0;
    char S[100];
    scanf("%c",&S[100]);
    fgets(S,sizeof S,stdin);
    while(S[i])
    {
        printf("%c",S[i]);
        i++;
    }
}
Saikrishna Rajaraman
  • 3,205
  • 2
  • 16
  • 29
  • Please see [ask]. You need to [edit] this question and tell us exactly what you want to do, show us what you tried, and tell us what results you got. –  Oct 01 '18 at 16:37
  • 1
    C uses zero-based indexing, expression &S[100] means, pointer to 101th element of an array of size 100. When you do scaf("%c", &S[100]), you read that one character and store it 1 byte past your buffer (probably the reason why you think there is missing character in output). Since fgets reads up to (size-1) bytes from input and stores terminating '\0' at the end, you will never see that byte that (fgets have written '\0' at position S[99]), your while loop will terminate at index 99 or before that if there are any '\0's in the buffer). – Tomas Pruzina Oct 01 '18 at 17:13

0 Answers0