دنبال کننده ها

۱۳۹۶ آذر ۱۲, یکشنبه

c - Dynamic Struct with Dynamic Matrix

[ad_1]



I'm having a little trouble doing a school project, and I can't post all my code here because it might be copied by my scoolmates.



I have created a Dynamic Struct called Messages with the variable inside it char ** phrases, int lines(number of msg at the moment), int heaplines(max number of lines my Char ** phrases can hold).



My program should work this way: it asks the user to insert messages, allocating memory to them and increasing the variable lines, which is the number of messages he has at the moment, if it reaches the max then I do an reallocation of +10 plus lines and it increases the heaplines. But my true problem is I cant allocate memory to the string the user has inserted because it gives me an error saying: Incompatible Pointers types "char **" and "char *".



MSG->phrases=(char*)malloc((tamphrase+1)*sizeof(char));



Allocating the lines for the matrix of char ** msg it works perfectly, but when I try to allocate memory for the string that is going to be inserted it gives me that error on that line of code above.



Btw, how can I increment the lines of the matrix of phrases?
For example: MSG->(phrases+i)=(char*)malloc((tamphrase+1)*sizeof(char));(I know this is wrong, but I hope you guys know what I'm trying to say)




[ad_2]

لینک منبع