The text below is selected, press Ctrl+C to copy to your clipboard. (⌘+C on Mac) No line numbers will be copied.
Guest
Error in program
By Guest on 6th August 2018 10:33:48 PM | Syntax: C | Views: 1



New paste | Download | Show/Hide line no. | Copy text to clipboard
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<stdlib.h>
  4.  
  5. char* remove_extra_space(char *s)
  6. int count_words(char *s)
  7.  
  8. main()
  9. {
  10.     char str[100];
  11.     gets(str);
  12.     printf("length of sentence: %d", strlen(str));
  13.     strcpy(str, remove_extra_space(str));
  14.     printf("\nwords are: ", count_words(str));
  15.     getch();
  16. }
  17.  
  18. int count_words(char *s)
  19. {
  20.     int count=1, i=0;
  21.     while(*(s+i)){
  22.         if(*(s+i)==' ')
  23.             count++;
  24.         i++;
  25.     }
  26.     return(count);
  27. }
  28.  
  29. char* remove_extra_space(char *s){
  30.     char *p;
  31.     int i=0,j=0;
  32.     p = malloc(strlen(s)+1);
  33.     while(*(s+i)){
  34.         while(*(s+i)==' ')
  35.             i++;
  36.         while(*(s+i)!=' ' && *(s+i)!='\0'){
  37.             *(p+j)= *(s+i);
  38.             i++;j++;
  39.         }
  40.         if(*(s+i)=='\0' && *(p+j-1)==' ')
  41.             j--;
  42.         *(p+j) = *(s+i);
  43.     }
  44.     return(p);
  45. }
  46.  
  47.  
  48. |||||||ERROR LOG|||||||
  49. ||=== Build file: "no target" in "no project" (compiler: unknown) ===|
  50. D:\Robinsworld\CSE\Programming\C & CPP\PROGRAMS\test4.c||In function 'remove_extra_space':|
  51. D:\Robinsworld\CSE\Programming\C & CPP\PROGRAMS\test4.c|8|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'main'|
  52. D:\Robinsworld\CSE\Programming\C & CPP\PROGRAMS\test4.c|19|error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token|
  53. D:\Robinsworld\CSE\Programming\C & CPP\PROGRAMS\test4.c|29|error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token|
  54. D:\Robinsworld\CSE\Programming\C & CPP\PROGRAMS\test4.c|45|error: expected '{' at end of input|
  55. ||=== Build failed: 4 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|



  • Recent Pastes

Advertise here

Advertise here