I am trying to take string user input from the user using c code and then add it to array of strings so that I could have a variable its first component be a word so if the variable called X then X[1] becomes full word which inputted to the array using prompt function like getstring but when I tried the code below it gave me error.
Can anyone help me restructure my code ?
#include <stdio.h>
#include "cs50.h"
#include <string.h>
string get_items();
bool check_items_add = true;
int main()
{
string units = get_items();
printf("%s\n", units[1]);
}
string get_items()
{
string items[] = get_string("Write market item: ");
while (check_items_add)
{
items += get_string("Write market item: ");
}
return items;
}
The line
does not make sense, because
get_stringwill only give you a single string, not several strings.I am not sure if I understood your question properly, but if you want to create an array of strings and fill it one string at a time with
get_string, then you can do this:This program has the following behavior: