For the code below, I am getting the
Segmentation fault (core dumped)
error message, can someone help me please?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void){
char s[] = "helloWorld";
int i;
for(i = 1; i < strlen(s); i++)
{
printf("Letter is %s\n", s[i]);
}
return(0);
}
is wrong,
%sexpects aconst char *, and you’re giving it achar. Change this line tosince the
%cformat specifier is intended for printing individual characters.Also, in C, arrays are zero-based, so you should initialize
ito zero usingi = 0;as well.