hey guys, i got a problem,
im a big java fan and i am doing a c program for a project for school. The program states that you have to enter a string and then display the number of charecters, words and spaces in the string
i have got it to successfully count the charecters, but when the words calculate, it displays how many spaces i allowed for the string
the program is below, with tags to help you understand my program, its not urgent, but i just cant get it to display the words and spaces properly
code is as follows:
thanks guys, hope you can find my syntax errorCode:Question 1 - Programming Assignment 2 // String Reader with analysis // By Matthew Potter 0314377 22/11/05 #include "stdio.h" #include "string.h" #include "conio.h" void main(void){ // start main // declaring variables char string[50]; char space = ' '; int *totalspace; int length, words; // taking user input printf("\nEnter a sentence that is less than 50 letters\n") ; gets(string); length=strlen(string); // lenghth of entered string totalspace=strchr(string, space); // blank space calculator words=sizeof(string); // word count puts(string); // Displaying Output To Screen printf("\nThe String %s Is %d Charaters Long\n",string,length) ; printf("\nThere Are %d Words In Your String\n",words); printf("\nThere Are %d Spaces In Your String\n",totalspace); } // end main



LinkBack URL
About LinkBacks


