Hi,
i am trying to simulate the concatenation of two strings using arrays. I am however running into segmentation fault error. I am not sure as to what this means as i am new to C.
Your help is appreciated.
Code:
#include<stdio.h>
/* function prototype */
void strconcat(char [],char[]);
main(){
/* declare variables */
char first[80];
char second[80];
int x = 0, c;
/* Get input */
printf("Enter first string: ");
while((c=getchar()) != 10){
first[x] = c;
x++;
}
x = 0;
printf("Enter second string: ");
while((c=getchar()) != 10){
second[x] = c;
x++;
}
strconcat(first,second);
}
void strconcat(char f[],char s[]){
/* declare local variables */
char c[80];
int i = 0,j = 0;
while(f[i] != 10){
c[i] = f[i];
i++;
}
while(s[j] != 10){
c[i] = s[j];
i++;
j++;
}
printf("The concatenated string is: %s",s);
}