Advertisement
Guest User

Untitled

a guest
Nov 21st, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. void str_cat(char s[], char k[]);
  5. void copy_string(char sours[], char destination[]);
  6.  
  7. int main()
  8. {
  9. char str[1000], sours[1000], destination[1000];
  10.  
  11. printf("Input a strig in sours\n");
  12. fgets(sours, 999, stdin);
  13.  
  14. int choice;
  15. printf("if you need copy input 1, if you need concatination input 2: ");
  16. scanf("%d", &choice);
  17.  
  18. switch (choice){
  19. case 1:
  20. copy_string(sours,destination);
  21. printf("The copy string: %s\n", destination);
  22. break;
  23. case 2:
  24. printf("Input a strig in str\n");
  25. fgets(str, 999,stdin);
  26.  
  27. str_cat(sours, str);
  28. printf("The string: %s\n", sours);
  29. break;
  30. default:
  31. printf("Error\n");
  32. }
  33.  
  34. return 0;
  35. }
  36. void copy_string(char sours[], char destination[])
  37. {
  38. int c = 0;
  39.  
  40. while (sours[c] != '\0'){
  41. destination[c] = sours[c];
  42. c++;
  43. }
  44.  
  45. destination[c] = '\0';
  46.  
  47. }
  48. void str_cat(char sours[], char str[])
  49. {
  50. int c = 0;
  51. int cc = 0;
  52.  
  53. if (strlen(sours) + strlen(str) <= 1000){
  54. while(sours[c] != '\n'){
  55. c++;
  56. }
  57.  
  58. int p;
  59. printf("do you need 'space'? 1 or 2: ");
  60. scanf("%d", &p);
  61. switch(p){
  62. case 1: sours[c] = ' ';
  63. c++;
  64. case 2: while(str[cc] != '\0'){
  65. sours[c] = str[cc];
  66. c++;
  67. cc++;
  68. }
  69. break;
  70. default: printf("Error");
  71. }
  72.  
  73. sours[c] = '\0';
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement