Skip to main content

First I need to mention that I learn c-codinghave been learning C coding for some time but would call memyself an intermediate beginner at best. So take what I say with the right amount of scepticism.

int MAXSIZE 

To define constants like buffersizesbuffer sizes it is better to use const int which make your Intention more clearintention clearer.

Also you should be more consistenttconsistent with the spaces aorundaround your arithmetic operations:

forFor example, strlen(inputStr) - 1 is clearer than strlen(inputStr)-1.

You should be constant wihtwith the way you use functions and how you intend their arguments:

f(arg1, arg2) instead of sometimes f (arg1,arg2) and sometimes f ( arg1, arg2 )f ( arg1, arg2 ).

In Additionaddition to these Pointspoints, which will only improve the readability of your code, I am pretty sure that you could copy directly from Inputinput into the array like this:

/* allocate space in the array for the string and copy it in */
array[i] = malloc((sizeof(char*)) *(strlen(inputStr)) + 1);
strncpy(array[i], inputStr, strlen(inputStr) + 1);

This way you can delete the intermediate step where you save the input into a separatseparate string and allocate (and free!) memory for it.

First I need to mention that I learn c-coding for some time but would call me intermediate beginner at best. So take what I say with the right amount of scepticism.

int MAXSIZE 

To define constants like buffersizes it is better to use const int which make your Intention more clear.

Also you should be more consistentt with the spaces aorund your arithmetic operations:

for example strlen(inputStr) - 1 is clearerstrlen(inputStr)-1

You should be constant wiht the way you use functions and how you intend their arguments:

f(arg1, arg2) instead of sometimes f (arg1,arg2) and sometimes f ( arg1, arg2 )

In Addition to these Points which will only improve the readability of your code I am pretty sure that you could copy directly from Input into the array like this:

/* allocate space in the array for the string and copy it in */
array[i] = malloc((sizeof(char*)) *(strlen(inputStr)) + 1);
strncpy(array[i], inputStr, strlen(inputStr) + 1);

This way you can delete the intermediate step where you save the input into a separat string and allocate (and free!) memory for it.

First I need to mention that I have been learning C coding for some time but would call myself an intermediate beginner at best. So take what I say with the right amount of scepticism.

int MAXSIZE 

To define constants like buffer sizes it is better to use const int which make your intention clearer.

Also you should be more consistent with the spaces around your arithmetic operations:

For example, strlen(inputStr) - 1 is clearer than strlen(inputStr)-1.

You should be constant with the way you use functions and how you intend their arguments:

f(arg1, arg2) instead of sometimes f (arg1,arg2) and sometimes f ( arg1, arg2 ).

In addition to these points, which will only improve the readability of your code, I am pretty sure that you could copy directly from input into the array like this:

/* allocate space in the array for the string and copy it in */
array[i] = malloc((sizeof(char*)) *(strlen(inputStr)) + 1);
strncpy(array[i], inputStr, strlen(inputStr) + 1);

This way you can delete the intermediate step where you save the input into a separate string and allocate (and free!) memory for it.

Source Link

First I need to mention that I learn c-coding for some time but would call me intermediate beginner at best. So take what I say with the right amount of scepticism.

int MAXSIZE 

To define constants like buffersizes it is better to use const int which make your Intention more clear.

Also you should be more consistentt with the spaces aorund your arithmetic operations:

for example strlen(inputStr) - 1 is clearerstrlen(inputStr)-1

You should be constant wiht the way you use functions and how you intend their arguments:

f(arg1, arg2) instead of sometimes f (arg1,arg2) and sometimes f ( arg1, arg2 )

In Addition to these Points which will only improve the readability of your code I am pretty sure that you could copy directly from Input into the array like this:

/* allocate space in the array for the string and copy it in */
array[i] = malloc((sizeof(char*)) *(strlen(inputStr)) + 1);
strncpy(array[i], inputStr, strlen(inputStr) + 1);

This way you can delete the intermediate step where you save the input into a separat string and allocate (and free!) memory for it.