create an array of strings

Posted on 2005-04-28
Last Modified: 2010-04-15
How would I go about creating an array of strings?
I have right now:

 char line[LINE_MAX];                                        // To store input line.
 char history[HIS_MAX][LINE_MAX];                            // History of commands.
  int  i =0, count, flag=0, his_count=0;

 if (line[i++] == '!') {                                 // If first character user entered was ! then use history
        count = 0;
        while (line[i++] != NULL) {
          count = count * 10;                                 // Find what index to use for history array
          count = count + ((int)argbuf[1] - 48);  }           //offset of ascii
        if (count < HIS_MAX-1 && history[count] != NULL)
          line = history[count];
        else {
          fprintf(stderr, "Syntax error in command.\n");
          flag = 1; } }
      else {
        if (his_count++ < HIS_MAX-1) {
          while (history[i] != NULL)
          history[i] = line; }
        else {
          for (i=0; i < HIS_MAX-1; i++)
            history[i] = history[i+1];
          history[i+1] = line; } }

But when I try to copy line into history, I get an error: incompatible types in assignment
what am I doing wrong?
Question by:v_wall78
    LVL 30

    Expert Comment

    You need to use the strcpy function to copy a string
    LVL 30

    Expert Comment

           if (count < HIS_MAX-1 && history[count] != 0)
    LVL 30

    Expert Comment

    Also, don't put a minus one on the if condition statement.
    And you should be checking for the first char equal to zero or just using strlen(str) != 0
           if (count < HIS_MAX && history[count][0] != 0)

    or ----

           if (count < HIS_MAX && strlen(history[count]) != 0)

    LVL 30

    Accepted Solution

    Don't treat a string like you do an integer.

    You can't make comparison with a string like you do an integer, and you can't copy it either.

    You need to use str??? functions to copy, compare, and assign data to a string.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Goodbye, so long 10 81
    Process does stop by itself 37 122
    Problem with form project 66 308
    How to design, and implement simple interface 5 117
    Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode ( They will have you believe that Unicode requires you to use…
    This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
    The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
    The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now