Thread: Simple text editor help

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    3
    Quote Originally Posted by tabstop View Post
    If result_from_strstr is a pointer to the middle of the array, and row_n is a pointer to the beginning of the array, then result_from_strstr - row_n tells you the index of that pointer in the array.
    First of all, thanks for the idea! I have a serious problem. This is the code I've written:

    Code:
    int i, row;
    void *index;
    char *row_n, *result, word[15], keystrokes[20][81];
    
    printf("Word to find: ");
    fgets(word, sizeof(word), stdin);
    
         for (i=0;i<20;i++)    /* 20 lines */
         {
             row_n=keystrokes[i];
             if ((result=strstr(keystrokes[i],word))!=NULL)     /* keystrokes[i]=&keystrokes[i][0] */
             {    
                 index=result-row_n;
                 row=i;
                 gotoxy(index,row);
             }
             else
            {
                 printf("There's No Such Word");
            }
         }
    My program crashes when I run this code. Is the code properly written? How can I find the index of that pointer in the array and what about the gotoxy(col,row) function?
    Last edited by Sartre; 01-17-2011 at 06:03 PM.

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by Sartre View Post
    Code:
    void *index;
    
                 index=result-row_n;
                 gotoxy(index,row);
    The variable index should be a int not a pointer.
    FYI: You need to remove the trailing linefeed to find a good match.

    Tim S.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to use FTP?
    By maxorator in forum C++ Programming
    Replies: 8
    Last Post: 11-04-2005, 03:17 PM
  2. Simple Text Parsing.. Long Time Since College
    By chops11 in forum C Programming
    Replies: 4
    Last Post: 10-07-2004, 04:00 PM
  3. Replies: 5
    Last Post: 02-01-2003, 10:58 AM
  4. text simple question
    By Unregistered in forum Game Programming
    Replies: 2
    Last Post: 04-26-2002, 09:45 AM
  5. simple text dialog ok cancel
    By Brian in forum Windows Programming
    Replies: 1
    Last Post: 02-12-2002, 02:20 AM