+ 1
Storing string values in a queue instead of numerical values
I would like to create a queue that stores strings values instead of numerical values, the user should be able to enqueue a sentence into the queue, E.g "I am doing laundry."
3 odpowiedzi
0
I don't have any code associated with this question because I don't know how to approach it so any help would be greatly appreciated
0
a string is an array of char.
So a array of strings is a 2-dimensional array of char.
https://www.codingame.com/playgrounds/14213/how-to-play-with-strings-in-c/array-of-c-string
https://code.sololearn.com/cSsTdhL2H3DX
0
You can use the same logic as with a numberic queue.
Just replace numbers with pointers to strings (char*).
In enqueue function allocate a copy of the string (use malloc and strcpy) and push a pointer to the allocated string at the end of a queue.
In dequeue function pop a pointer to string from the begining of a queue, copy string to user buffer and free it.