use c language only to solve this porblem -------------------------- Have the function StringChallenge(str) take the str string parameter being passed and return the number of words the string contains (e.g. "Never eat shredded wheat or cake" would return 6). Words will be separated by single spaces. Examples Input: "Hello World" Output: 2 Input: "one 22 three" Output: 3
you have the following code what edits can you do
#include <stdio.h>
#include <string.h>
void StringChallenge(char str[]) {
// code goes here
printf("%s", str);
}
int main(void) {
// keep this function call here
StringChallenge(gets(stdin));
return 0;
}
//Code in C
#include <stdio.h>
#include<stdlib.h>
#include <string.h>
int StringChallenge(char str[])
{
int length,wordcount=1;
length=strlen(str);
for(int i=0;i<length;i++)
{ if(str[i]==' '||str[i]=='\t')
wordcount++;
}
printf("%s", str);
return wordcount;
}
int main(void)
{
int words;
char str[80];
printf("Enter any string : ");
fgets(str, 80, stdin);
words=StringChallenge(str);
printf("Number of words = %d",words);
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.