Thread: Text file editor code

  1. #1
    Registered User
    Join Date
    Jun 2006

    Text file editor code

    Hey there, im a newbie and first time poster .... so please be nice!!

    Im working on an assignment to create a basic text file editor which was all going dandy until i've realised the functions I've been using to get a line number off user produce wrong results

    printf("\nLine No: ");
    scanf("%d", &linenum);
    printf("You entered line no. %d", linenum);

    printf("\nLine: ");
    fscanf(stdin, "%d", &linenum);
    printf("Line No chosen is %d", linenum);
    these both added '69' on to whatever is entered when printing linenum again

    any helpful suggestions would be most appreciated!!


  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    United States
    There really is nothing wrong with what you posted, so please post some more code than that.

  3. #3
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    is linenum declared as a char? should be int, but if it was char it
    should only add on 48 to your value...
    No No's:
    fflush (stdin); gets (); void main ();

    Example of fgets (); The FAQ, C/C++ Reference

    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition

    ASCII stupid question, get a stupid ANSI

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    You're probably using %c in the [f]scanf() calls. Or maybe you're using %x or %o or something in the printf() calls.

    Post some of the surrounding code if you can't get it to work.

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell

    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ:

    My website:
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  2. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  3. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 10:51 PM
  4. checking values in a text file
    By darfader in forum C Programming
    Replies: 2
    Last Post: 09-24-2003, 02:13 AM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM