Printing Lines to .txt File

This is a discussion on Printing Lines to .txt File within the C Programming forums, part of the General Programming Boards category; What I have done is basically laid out a 10x10 table filled with zeroes in every position. Now what I ...

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    12

    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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    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...
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Registered User
    Join Date
    Mar 2008
    Posts
    43
    This might help you without using ncurses (only tested on linux).
    Code:
    #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);
        va_end(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

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