Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include<stdio.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. void del(char* str, int index)
  6. {
  7. for (int i = index+1; i<=strlen(str); i++)
  8. {
  9. str[i-1] = str[i];
  10. }
  11. }
  12.  
  13. int main()
  14. {
  15. int i,n,f = 0;
  16. char str[255] = "";
  17. int start = 0,finish = 0;
  18.  
  19. printf("Enter string : \n");
  20. gets(str);
  21. printf("Enter number of word of delete : ");
  22. scanf("%d", &n);
  23.  
  24.  
  25. if(n == 1 && str[0] != ' ')
  26. {
  27. start = 0;
  28.  
  29. }
  30. else if(n==1)
  31. {
  32. for(int i=0;i<strlen(str)-1;i++)
  33. {
  34. if((str[i] == ' ') && (str[i+1] != ' ') )
  35. {
  36.  
  37. start = i+1;
  38. break;
  39. }
  40. }
  41. }
  42. else
  43. {
  44. int count = 0;
  45. for(int i=0;i<strlen(str)-1;i++)
  46. {
  47. if(str[i] == ' ' && str[i+1] != ' ')
  48. {
  49. count++;
  50. if(count == n-1)
  51. {
  52. start = i+1;
  53. break;
  54. }
  55. }
  56.  
  57.  
  58. }
  59. }
  60.  
  61.  
  62.  
  63. printf("start = %d\n",start);
  64.  
  65. while( str[start] != ' ' && str[start] != '\0')
  66. {
  67. del(str,start);
  68. }
  69. printf("result string = %s", str);
  70.  
  71.  
  72.  
  73. return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement