Thread: Printing Lines to .txt File

  1. #1
    Registered User
    Join Date
    Aug 2008

    Printing Lines to .txt File

    What I have done is basically laid out a 10x10 table filled with zeroes in every position. Now what I want to do is have the user input a line number, and then fill in the 10 columns with actual numbers. Is there a command in C that will let me move the cursor to the next line without printing a new line?

    The idea I had was to have a loop run a number of times set by the line number. So say we choose line number 7. The loop would run 7 times, printing a "\n" every time, but this will create a blank line in between, I just want the cursor to move down one without printing a blank line.

  2. #2
    "I Win!" by U. Lose vart's Avatar
    Join Date
    Oct 2006
    Rishon LeZion, Israel
    If I understand correctly - what you want to achieve is impossible to do using only standard C - you may want to have a look at the ncurses library...
    To be or not to be == true

  3. #3
    Registered User
    Join Date
    Mar 2008
    This might help you without using ncurses (only tested on linux).
    #include <stdio.h>
    #include <stdarg.h>
    void print_pos(int x, int y, char * msg, ...)
        /* sets the cursor */
        fprintf(stdout, "%c[%d;%df", 0x1B, y, x);
        va_list arg;
        va_start(arg, msg);
        vfprintf(stdout, msg, arg);
        /* call this outside of the function */
        /* fflush(stdout); */

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  2. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM