Storing string values in a queue instead of numerical values | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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."

7th Mar 2020, 7:42 PM
Jergan Hector
Jergan Hector - avatar
3 Answers
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
7th Mar 2020, 7:59 PM
Jergan Hector
Jergan Hector - avatar
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
7th Mar 2020, 8:02 PM
sneeze
sneeze - avatar
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.
7th Mar 2020, 9:07 PM
andriy kan
andriy kan - avatar