A
arkobose
my earlier post titled:
"How to input strings of any lengths into arrays of type: char
*array[SIZE] ?"
seems to have created a confusion. therefore i paraphrase my problem
below.
consider the following program:
#include<stdio.h>
#define SIZE 1
int main()
{
char *array[SIZE];
scanf("%s", array[0]); // type a string of any length whatsoever.
for(int i = 0; *(array[0] + i) != '\0'; i++)
printf("%c", *(array[0] + i));
return 0;
}
when you run this program, you will find that the "printf" outputs the
whole string which you entered through "scanf", no matter how long your
string was.
now suppose you change the constant SIZE to some bigger value, 4, for
example, and then modify the program to this:
#include<stdio.h>
#define SIZE 4
int main()
{
char *array[SIZE] = {"string of any size", "type",
"praetertranssubstantiationalistically", "another string"};
for(int i = 0; i < SIZE; i++){
for(int j = 0; *(array + j) != '\0'; j++){
printf("%c", *(array + j));
}
printf("\n");
}
return 0;
}
then this program will output the strings with which the array has been
initialized exactly.
but if you want that the strings be entered at run time by user, rather
than be given at initialization as above, then how do you do this?
that is, during execution you type your strings one by one and they get
stored exactly as in the above program.
any ideas?
-arko
"How to input strings of any lengths into arrays of type: char
*array[SIZE] ?"
seems to have created a confusion. therefore i paraphrase my problem
below.
consider the following program:
#include<stdio.h>
#define SIZE 1
int main()
{
char *array[SIZE];
scanf("%s", array[0]); // type a string of any length whatsoever.
for(int i = 0; *(array[0] + i) != '\0'; i++)
printf("%c", *(array[0] + i));
return 0;
}
when you run this program, you will find that the "printf" outputs the
whole string which you entered through "scanf", no matter how long your
string was.
now suppose you change the constant SIZE to some bigger value, 4, for
example, and then modify the program to this:
#include<stdio.h>
#define SIZE 4
int main()
{
char *array[SIZE] = {"string of any size", "type",
"praetertranssubstantiationalistically", "another string"};
for(int i = 0; i < SIZE; i++){
for(int j = 0; *(array + j) != '\0'; j++){
printf("%c", *(array + j));
}
printf("\n");
}
return 0;
}
then this program will output the strings with which the array has been
initialized exactly.
but if you want that the strings be entered at run time by user, rather
than be given at initialization as above, then how do you do this?
that is, during execution you type your strings one by one and they get
stored exactly as in the above program.
any ideas?
-arko