Write a C function that counts the number of words in a string.?
348911
#include <stdio.h>\n#include <strings.h>\n\nint\nmain(int argc, char* argv[])\n{\n  char *token, *string = argv[1];\n  int count = 0;\n\n  while ((token=strtok(string, "&#92;t ")) != 0) {\n    count++;\n    string = 0;\n  }\n    \n  printf("String has %d words&#92;n", count);\n\n  return 0;\n}\n\n\nAnd to show that it works:\n\n$ cc cw.c\n\n$ a.out "this is a simple test"\nString has 5 words
391700
I came up with 80 words (not including 1 and 2 letter words) before I got tired of looking. Here's my list.\n\nAir,art,ate,act,are,arc,ace,\ncat,car,eat,ear,hot,her,hit,\nhoe,hat,hie,ice,ire,kit,ore,\noar,rat,roe,rot,tar,tea,toe,\nthe,arch,char,cart,core,cake,\ncote,chat,coat,care,cork,each,\nhear,heat,hart,hike,hire,hare,\nhair,hate,itch,okra,rich,rack,\nrote,rice,race,rate,tear,trek,\ntake,tack,tore,tick,tire,tier,\nchoke,cheat,chore,croak,chart,\nchair,cater,crate,earth,heart,\nreach,roach,track,teach,torch,\ntrick
359046
#include <ctype.h>\n#include <stdio.h>\n#include <stdlib.h>\n\nstatic char *article[] = { "the","a", "one", "some", "any" };\nstatic char *noun   [] = { "boy","girl", "dog", "town", "car" };\nstatic char *verb   [] = { "drove","jumped", "ran", "walked", "skipped" };\nstatic char *prep   [] = { "to", "from", "over", "under", "on" };\n\nint\nmain()\n{\n  int asize = sizeof(article)/sizeof(article[0]);\n  int nsize = sizeof(noun)/sizeof(noun[0]);\n  int vsize = sizeof(verb)/sizeof(verb[0]);\n  int psize = sizeof(prep)/sizeof(prep[0]);\n\n  char buff[100];\n  for (int i=0; i<20; i++) {\n    (void)sprintf(buff, "%s %s %s %s %s %s.",\n      article[rand()%asize],\n      noun[rand()%nsize],\n      verb[rand()%vsize],\n      prep[rand()%psize],\n      article[rand()%asize],\n      noun[rand()%nsize]);\n    *buff = toupper(*buff);\n    (void)printf("%s&#92;n", buff);\n  }\n  return 0;\n}\n\n\n$ a.out\nSome town walked to a dog.\nThe car ran from any dog.\nAny boy drove under any town.\nOne girl jumped under the girl.\nOne car jumped to one girl.\nAny boy skipped over a dog.\nAny town jumped from some town.\nThe town ran from the town.\nOne car walked to any town.\nOne town ran over one boy.\nAny town jumped on the car.\nSome dog skipped from a boy.\nSome girl skipped over a boy.\nA car walked over some girl.\nThe car jumped from a girl.\nThe boy skipped on the town.\nAny car walked from one girl.\nAny dog ran to a town.\nA car jumped under some car.\nSome boy walked to the car.
391107
USe the function "CountIF"\n\ne-mail me for more details
1013473
1) 120 words\n\n2)12345 (these represent teh letters) first make all the words with 1 at teh beginning then 2 then 3 and so on
272397
Yes its so easy. just start from 1 and write till 100 in words i.e\n\none\ntwo\nthree\nfour\nfive\n.\n.\n.\n.\nhundred\n\n:)
78294
I dont exctly remenber how to do it, but you should check out "tokens" \nYou can take a string and divide it in tokens, (you can set you own division point, in you case " ") That way you could easily count how many blanks in the text.\n\nHope it helps..
881644
Something like this:\n\nint **myArray;\nint s1,s2,i;\n\nprintf("Input row size: ");\nscanf("%d",&s1);\nprintf("Input column size: ");\nscanf("%d",&s2);\n\nmyArray[0] = malloc(s1*s2*sizeof(int));\nif (myArray[0] != NULL ) {\n  for (i = 0;i<s1,i++) {\n         myArray[i] = (i * s2) + myArray[0];\n  }\n}\n\nmyArray can then be used as normal\n\nmyArray[2][4] = 20;
397803
/*\n\ni need to know an example of writting a program in c\nlanguage under linux using threads?\n\nwrite aprogram to calculate the result of the equation\nY=3sin(x)+6cos(x)+5x2 so each term accomplished by a\nthread. The main thread will calculate the result.\n\n*/\n\n\n#include <pthread.h>\n#include <math.h>\n#include <stdlib.h>\n#include <stdio.h>\n\n/* static global location -- all threads will read */\nstatic double x;\n\nstatic void*\nthree_sinx(void*p)\n{\n  double* result = (double*)p;\n  *result = 3 * sin(x);\n  return 0;\n}\n\nstatic void*\nsix_cosx(void*p)\n{\n  double* result = (double*)p;\n  *result = 6 * cos(x);\n  return 0;\n}\n\nstatic void*\nfive_x_squared(void*p)\n{\n  double* result = (double*)p;\n  *result = 5 * x * x;\n  return 0;\n}\n\n/*\n *\n * Y = 3sin(x) + 6cos(x) + 5x2\n *\n */\n\nint\nmain(int argc, char* argv[])\n{\n  double result[3]; /* one location for each thread */\n  pthread_t tid[3];\n  void *r;\n  int i;\n\n  /* Set "x" to double value passed in on command line */\n  x = argc>1 ? strtod(argv[1], 0) : 0;\n\n\n  /*\n   *  Since result areas are distinct, no mutex needed\n   */\n  if (pthread_create(&tid[0], NULL,\n    three_sinx, &result[0]) != 0) {\n    perror("pthread_create[0]"), exit(-1);\n  }\n\n  if (pthread_create(&tid[1], NULL,\n    six_cosx, &result[1]) != 0) {\n    perror("pthread_create[1]"), exit(-1);\n  }\n\n  if (pthread_create(&tid[2], NULL,\n    five_x_squared, &result[2]) != 0) {\n    perror("pthread_create[2]"), exit(-1);\n  }\n\n  /* Synchronize on the completing child threads */\n  for (i=0; i<3; i++) {\n    if (pthread_join(tid[i], &r) != 0) {\n      perror("pthread_join");\n      exit(-1);\n    }\n  }\n\n  /* main thread will now combine the result */\n  printf("For y=3sin(x)+6cos(x)+5x2, when x=%f, y=%f&#92;n",\n      x, result[0]+result[1]+result[2]);\n\n  return 0;\n}\n\n\n\nTo show that it works:\n\n$ cc pthr.c -lpthread -lm\n\n$ a.out 3.14159\nFor y=3sin(x)+6cos(x)+5x2, when x=3.141590, y=43.347947\n\n$ a.out 0\nFor y=3sin(x)+6cos(x)+5x2, when x=0.000000, y=6.000000
825400
Two words:\nStill Counting
1110691
Here is something I came up with quickly ( not fully complete, I will leave that to you ! ) \n\nThis quick bit of code will give you a start ( hopefully and no recursion ).\n\nPlease note that this is not complete and you will get a memory leak in swap function ( easily fixed btw ! ).\n\n#include "stdafx.h"\n#include "stdio.h"\n#include "string.h"\n\nvoid manipulate( char* pString, int index );\nchar* swap( char* pString, int pos );\n\nchar pod[255];\n\n\nint main(int argc, char* argv[])\n{\n\n  char* p = "abc";\n  memcpy( pod, p, strlen( p ) );\n  for( int i = 0; i < strlen( p ); i ++ )\n  {\n    manipulate( pod, strlen( p ) );\n  }\n  return 0;\n}\n\n\nvoid manipulate( char* pString, int index )\n{\n  int i = 1;\n  char* p;\n  p = pString;   \n  while( index > 1 ) \n  {\n    p = swap( p, i );\n    index--;\n    i++;\n    memcpy( pod, p, strlen( pString ) );\n    printf( "%s&#92;n", p );\n  }\n}\n\nchar* swap( char* pString, int pos )\n{\n  char* p = new char[ strlen(pString) + 1 ];\n  memset( p, '&#92;0', strlen( pString ) + 1);\n  memcpy( p, pString, strlen( pString ) + 1 );\n  char temp = p[pos];\n  p[pos] = pString[pos-1];\n  p[pos-1] = temp;\n  return p;\n}
696126
How the F*** would I F***in' know ? I don't F***in' count  every F***ed up F***in' word !
162888
if u need any programs in C language..then please send me the questions..I will mail u the solution code..
389395
no. \n\nthose programs actually count blank spaces. \n\nso in between each of these words is a blank space. and each blank space actually has an ASNI or ASCII conversion. i forget which, like a blank space actually on a web site is  \n\nyou count those and you get the word count.
76848
Short answer: At least 81,520 words.\n\nMuch longer answer: To give a rather rough estimate, I used a wordlist that I have stored on my computer useful for allowing computer programs to recognize English words and determined it's size.  \n\nIt contained 81,520 words.  This is, almost certainly, a lower bound as there are very likely words which the wordlist does not contain yet are words anyway.  Also, it won't detect science-jargon words (for example deoxyribose from DNA would not be included).\n\nHowever, the 81,000 figure ought to cover most commonly-used words.
315617
void StrReverse4(char *str)\n{\n    if(*str)\n    {\n        StrReverse4(str+1);\n        putchar(*str);\n    }\n}\n\nTry this code it might work
935645
main() { static char *a="n0body"; char b[512],*c,*d;\n  while (c=gets(a)) for (d=a;c;*c^=*d,c++,d=*++d?d:a);\n  printf ("%s&#92;n",b);}\n\n\nhappy?