Hi all:
I am new here as in C.
I want to store some strings in an array and i did, but when I show in the screen
only shows me the last string i introduce, here is my C source code:
#include "stdio.h"
#define LENG 45;
char *readString(char *string,int n); // function where read a string and return it
int main(void){
char string[LENG+1] , *ptrString[3];
int conunter;
// Here i am storing
for(counter=0;counter<3;counter++){
printf("String %d: ",counter+1);
ptrString[counter]=readS(string,LENG);//Storing in my string array
}
//Here i send to print in screen the array of strings
for(counter=0;counter<3;counter++){
printf("String[%d]: %s\n",counter+1,ptrString[counter]);
}
return 0;
}
//Here is readS
char *readS(char *string, int n){
char c;
int i=0;
while(1){
car=getchar();
if(car==' \n ' || i>n ) break;
string[i]=car;
i++;
}
string[i]=' \0 ' ;
return string;
}
/*
ok if i make this
String 1: Hi
String 2: how
String 3: are
show this
String 1: are
String 2: are
String 3: are
*/
Please help me.
Krann.