Hi I am having some trouble with a dynamically allocated (malloc) array of strings to print the array and stop printing when a particular word…

Hi I am having some trouble with a dynamically allocated (malloc) array of strings to print the array and stop printing when a particular word appears. i used a while loop and it prints but it doesnt stop when it reaches the word "scoop" as show below

int numorders;
int Scoops;
char**Icecream;
int i,a,b;
//scans in cases
scanf("%d",&numorders);
int row = numorders+1;
int col = 20;

Icecream = malloc(sizeof(char)*row);

for(i=0;i{
for(a=0;a{
Icecream[a]= malloc(sizeof(char)*col);
scanf("%s",Icecream[a]);
printf("%s",Icecream[a]);
while(Icecream[a]!= "scoop")
{
printf("%s",Icecream[a]);
}

I want to use a SIMILAR code as the above since it is MY work, but i need some help understanding how to make sure the while loop actually works because it prints out this (which is wrong)

"DoubleDoubleScoopTripleTripleQuadrupleQuadrupleScoopScoop" 

it should be printing out:

Double Scoop

Triple Scoop

Quadruple Scoop. 

thanks in advance

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply