Last active
August 29, 2015 14:22
-
-
Save darkodemic/2f6c74506d12f43deadb to your computer and use it in GitHub Desktop.
Ucitavanje dva niza i spajanje njih, zatim okretanje istog i ispis njega
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Compiled using GCC 5.1 | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
//preprocessor | |
void reverse(char s[], int s3l){ | |
char r[s3l]; | |
int c, d; | |
for (c = s3l - 1, d = 0; c >= 0; c--, d++)r[d] = s[c]; | |
r[d] = '\0'; | |
printf("Reversed string3 je %s",r); | |
} | |
int main(){ | |
printf("Unesite maksimalnu duzina nizova: "); | |
int n=0; | |
scanf("%d",&n); | |
char string1[n], string2[n], string3[2*n]; | |
printf("Unesite string1: "); | |
scanf("%s",string1); | |
puts(""); | |
printf("Unesite string2: "); | |
scanf("%s",string2); | |
strncpy(string3,string1,sizeof(string1)); | |
char *sp; | |
sp = &string3[strlen(string1)]; | |
strncpy(sp,string2,sizeof(string2)); | |
printf("string3 is %s\n",string3); | |
int s3l = strlen(string3); | |
reverse(string3,s3l); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment