I think my program is right but its showing an error "Segmentation fault(core dumped)". What is the problem?
#include<stdio.h>
#include<cs50.h>
#include<ctype.h>
#include<string.h>
int main(void)
{
string s="I am a good boy";
int len=strlen(s);
int word=0;
for(int i=0;i<len;i++)
{
s[i]=toupper(s[i]);
if(s[i]>=65 && s[i]<=90)
{
word++;
}
}
printf("%i",word);
}
expected output:
11
actual output:
segmentation fault(core dumped)
EDIT: It seems using char[] works. On another note, somehow, the above code works fine when it is on another function, i.e not int main(void)
.