Advertisement
Guest User

gang gang skrt skrt

a guest
Oct 22nd, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. void replace (char *, char *, char *);
  2.  
  3. int main(int argc, char *argv[]){
  4. FILE *f = fopen("Input.txt", "r");
  5. FILE *output =fopen("Dante.txt", "w");
  6. char str[500];
  7.  
  8. //alerts user if file doesn't exist
  9. if (f == NULL){
  10. printf("File not exist.\n");
  11. exit(0);
  12. }
  13.  
  14. //Changing the words to the new words in the file
  15. while(fgets(str, 500, f)){
  16. for(int i = 0; i < 500; i++){
  17. if(strstr(str, "Inferno") != NULL){
  18. replace(str, "Inferno", "Paradiso");
  19. }
  20. if(strstr(str, "In dark woods") != NULL){
  21. replace(str, "In dark woods", "using Windows 8.1");
  22. }
  23. if(strstr(str, "those woods") != NULL){
  24. replace(str, "those woods", "Windows 8.1");
  25. }
  26. if(strstr(str, "to enter") != NULL){
  27. replace(str, "to enter", "to use 8.1");
  28. }
  29. if(strstr(str, "crest") != NULL){
  30. replace(str, "crest", "screen");
  31. }
  32. if(strstr(str, "Below a hill") != NULL){
  33. replace(str, "Below a hill", "Before a monitor");
  34. }
  35. if(strstr(str, "shoulders") != NULL){
  36. replace(str, "shoulders", "GUI");
  37. }
  38. if(strstr(str, "planet") != NULL){
  39. replace(str, "planet", "Shakespeare");
  40. }
  41. }
  42. fprintf(output,"%s", str);
  43. }
  44.  
  45. fclose(f);
  46. return 0;
  47. }
  48.  
  49.  
  50. void replace(char * o_string, char * s_string, char * r_string) {
  51.  
  52. //a variable to replace things
  53. char buffer[1000];
  54.  
  55. //to store the pointer returned from str
  56. char * ch;
  57.  
  58. //exit condition
  59. if(!(ch = strstr(o_string, s_string)))
  60. return;
  61.  
  62. //copy all the content to buffer before the first occurrence of the search string
  63. strncpy(buffer, o_string, ch-o_string);
  64.  
  65. //prepare the buffer for appending by adding a null to the end of it
  66. buffer[ch-o_string] = 0;
  67.  
  68. //append using sprintf function
  69. sprintf(buffer+(ch - o_string), "%s%s", r_string, ch + strlen(s_string));
  70.  
  71. //empty o_string for copying
  72. o_string[0] = 0;
  73. strcpy(o_string, buffer);
  74.  
  75. //pass recursively to replace other occurrences
  76. return replace(o_string, s_string, r_string);
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement