Hi I am new to C (been working with it for about 2 months by myself)
and I have a problem I found an exercise where i am to create a twodimensional array of strings and rearrange after taking in consideration some criteria.... Anyway I am in the beginning and I have allocated space for my array and read the strings but for some reason it prints only the first 3 letters of each string....
Code:
#include <stdio.h>
#define STR_LEN 25
void creation(char **,int);
main()
{
char **string;
int i,size;
printf("How many rows do you want? ");
scanf("%d",&size);
fflush(stdin);
string=(char **) malloc(size*sizeof(char *));
creation(string,size);
for (i=0;i<size;i++)
fputs(*(string+i),stdout); //i've also tried printf("%s",*(string+i));
system("pause");
}
void creation(char **str,int size)
{
int i;
for(i=0;i<size;i++) {
*(str+i)=(char *) malloc(STR_LEN*sizeof(char));
printf("String No%d: ",i+1);
fgets(*(str+i),sizeof(*(str+i)),stdin);
fflush(stdin);
}
}
If someone can help me I d really appreciate it...Oh and if someone can explain me what is better for printing (printf,fputs....) and reading (sscanf,scanf,fgets,....)