Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- void str_cat(char s[], char k[]);
- void copy_string(char sours[], char destination[]);
- int main()
- {
- char str[1000], sours[1000], destination[1000];
- printf("Input a strig in sours\n");
- fgets(sours, 999, stdin);
- int choice;
- printf("if you need copy input 1, if you need concatination input 2: ");
- scanf("%d", &choice);
- switch (choice){
- case 1:
- copy_string(sours,destination);
- printf("The copy string: %s\n", destination);
- break;
- case 2:
- printf("Input a strig in str\n");
- fgets(str, 999,stdin);
- str_cat(sours, str);
- printf("The string: %s\n", sours);
- break;
- default:
- printf("Error\n");
- }
- return 0;
- }
- void copy_string(char sours[], char destination[])
- {
- int c = 0;
- while (sours[c] != '\0'){
- destination[c] = sours[c];
- c++;
- }
- destination[c] = '\0';
- }
- void str_cat(char sours[], char str[])
- {
- int c = 0;
- int cc = 0;
- if (strlen(sours) + strlen(str) <= 1000){
- while(sours[c] != '\n'){
- c++;
- }
- int p;
- printf("do you need 'space'? 1 or 2: ");
- scanf("%d", &p);
- switch(p){
- case 1: sours[c] = ' ';
- c++;
- case 2: while(str[cc] != '\0'){
- sours[c] = str[cc];
- c++;
- cc++;
- }
- break;
- default: printf("Error");
- }
- sours[c] = '\0';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement