i have this c++ code and i wondered how ot would be in c

    #include <vector> // for vector
    #include <sstream> // for stringstream
    #include <iostream>
    #include <string>

    using namespace std;

    int main()
    {
        stringstream ss;
        string input, temp;
        vector<string> comand;
        cout << ">: ";
        getline(cin, input);

        ss << input;    // brake up line and put each part into the vector
        while( ss >> temp)
        {
          comand.push_back(temp);
        }
            // display vector
        for(size_t i = 0; i < comand.size(); i++)
        cout << comand[i] << endl;

        cin.get(); // pause program
        return 0;
     }

what is does it takes in an input from the user and then brake it up into keywords and then display them again.

i used this type of program to make my own terminal program. so how is this code going to be in C

thanks....

Yes, you would need to create a dynamic array of strings depending on how many are created from parsing the input string.
The program would count the strings and display them one-by-one.

call fgets() to get user input, then strtok() to break it up into individual words. I would just statically allocate the array of pointers to strings, for example char* strings[255] = {0}; . You could, as previously mentioned, also use a dynamically allocated array of pointers char** strings = 0, but then you need to call malloc() and realloc() to expand the array to the desired size each time you want to add a new string to it. For small amounts of strings its just simpler and better to just use static allocation.

Mmm thanks i understand this, thanks, i am more of a c++ guy. dont know why, just like the language.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.