i have a code assignment which require a few code to be writen (i m new to c programming)
anyway heres the question, need to perfect it
first one,
Code:
write a c program to count the number of words in its input, where a"ward" is defined as any continuous sequence of non-whitespace characters
example:
input:"+++ --- hi bye 879+3"
output:" the string has 5 words.
("+++","---","bye", and "879+3")
heres my code
Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
char str[40];
int c;
int i,num=0;
int space;
gets(str);
c=strlen(str);
for(i=0;str[i]!='\0';i++)
{
if(str[i]==' '&&(str[i+1]!=' '))
{
num++;
}
}
if(str[0]==' ')
{
printf("The string has %d words ",num);
system("pause");
}
else
{
printf("The string has %d words",num);
printf("\n\n");
system("pause");
}
}
2 more code posted below
the 3rd program i have no idea how to write at all
please help me asap
i'm using dev c++ to write the code
thankyou v. much!