L
linguae
Hello. In my C program, I have an array of character pointers. I'm
trying to input character strings to each index of the character
pointer array using scanf(), but when I run the program, I get
segmentation faults and core dumps. The problem occurs when the
program calls scanf(). I don't know what is wrong with it.
Here is my code:
#include "stdio.h"
#define SIZE 5
void input(char *string, char *string2);
int main(void)
{
char *string[SIZE], *string2[SIZE];
int counter;
for(counter = 0; counter <= SIZE - 1; counter++)
input(string[counter], string2[counter]);
putchar('\n');
for(counter = 0; counter <= SIZE - 1; counter++)
printf("%s %s\n", string[counter], string2[counter]);
return 0;
}
void input(char *string, char *string2)
{
printf("Enter string 1: ");
scanf("%s", string);
printf("Enter string 2: ");
scanf("%s", string2);
}
Thanks in advance.
trying to input character strings to each index of the character
pointer array using scanf(), but when I run the program, I get
segmentation faults and core dumps. The problem occurs when the
program calls scanf(). I don't know what is wrong with it.
Here is my code:
#include "stdio.h"
#define SIZE 5
void input(char *string, char *string2);
int main(void)
{
char *string[SIZE], *string2[SIZE];
int counter;
for(counter = 0; counter <= SIZE - 1; counter++)
input(string[counter], string2[counter]);
putchar('\n');
for(counter = 0; counter <= SIZE - 1; counter++)
printf("%s %s\n", string[counter], string2[counter]);
return 0;
}
void input(char *string, char *string2)
{
printf("Enter string 1: ");
scanf("%s", string);
printf("Enter string 2: ");
scanf("%s", string2);
}
Thanks in advance.