moving cursor to the next line

This is a discussion on moving cursor to the next line within the C Programming forums, part of the General Programming Boards category; I have a pogram that reads values in a grid from a file into a two dimensional array of characters ...

  1. #1
    Unregistered
    Guest

    Unhappy moving cursor to the next line

    I have a pogram that reads values in a grid from a file into a two dimensional array of characters and then it needs to read the line after the grid into another array of characters. So, my question is, once I read all the chars into my first 2d array, how do I get the cursor to move to the next line to begin reading in the next char into the second array? I am thoroughly confused and at the end of my rope. Any help would be greatly appreciated.

    Doug

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Perhaps a look at the file would help me understand your problem better and give you a specific solution, but something like this doesn't work?
    Code:
    for ( x = 0; x < ROW; x++ )
      for ( y = 0; y < COL; y++ )
        fscanf ( fp, "%c", &array[x][y] );
    fgets ( array2, sizeof array2, fp );
    -Prelude
    My best code is written with the delete key.

  3. #3
    Unregistered
    Guest
    d'oh...yes, a copy of the file would be a good idea... sorry 'bout that. here it is:

    8 8
    ---WWW--
    ---W1W--
    WWWWBW--
    W2-BOWWW
    WWWBPB4W
    --W-WWWW
    --W3W---
    --WWW---
    OU PR OD PL OL PL OL PU PL PL PD

    Ok, so here's the description. Although you can't tell, the two numbres at the top of the file are the row and column numbers. The next thing below is the map that I scanf'd into a 2d array. The following line is what I want to store into another array, but the cursor stops right after it reads the last element of the map into the array. Sorry about the formatting.

    Oh, and we can't use string functions yet because this project came before we covered it in class. And we haven't dealt with fscanf yet so it's pretty much off limits too.

    Doug

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    95
    so what command are you using to read the chars from the file? how bout posting the code or small part of it and that way I can understand exactly what is going on and what you can and cant use.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Moving cursor to the end of line
    By behzad_shabani in forum C Programming
    Replies: 5
    Last Post: 05-30-2008, 12:41 PM
  2. Reading a buffer line by line, while using system read
    By Hammad Saleem in forum C Programming
    Replies: 9
    Last Post: 05-27-2008, 05:41 AM
  3. line number on a rich edit control
    By rakan in forum Windows Programming
    Replies: 1
    Last Post: 02-18-2008, 06:58 AM
  4. Trouble replacing line of file
    By Rpog in forum C Programming
    Replies: 4
    Last Post: 04-19-2004, 10:22 AM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21