Thread: Quick Question.

  1. #1
    Registered User SavesTheDay's Avatar
    Join Date
    Jan 2002

    Quick Question.

    #include <stdio.h>
    #include <string.h>

    int tall,wide,size,x=0;
    char line[100],temp[100];
    FILE *ifp;

    printf("\n\n Opening OBJECT.DAT ");

    if ((fopen("object.dat", "r")) == NULL)
    printf("\n error opening file object.dat ");

    printf("\n %s",line);


    I'm using this code to open up "object.dat"...then i want to read in the firstline of this going to count backwards through the characters...and stick the first set in one variable (temp), then set the int tall=atoi(temp)...the object.dat is going to look like:

    "400 200"

    and i have to read both of those memories into 2 int variables...Can anyone add a proper fgets line to my above code to make it read the line in properly..i couldnt get it to work...i also need to stick a null pointer wherever the space occurs..can anyone help real fast? Thanks.

  2. #2
    Registered User SavesTheDay's Avatar
    Join Date
    Jan 2002
    Well, I got my fgets() working...but how do I recognize when I come across a space in my line? What is the space character...when I come across a space, I want to stop...

  3. #3
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    i think using sscanf instead might help.

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    If you want to stop at the first space you can either just use fscanf or combine fgets and sscanf:
    fscanf ( line, sizeof line, fp );
    sscanf ( line, "%s", temp );
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Very quick math question
    By jverkoey in forum A Brief History of
    Replies: 8
    Last Post: 10-26-2005, 11:05 PM
  2. very quick question.
    By Unregistered in forum C++ Programming
    Replies: 7
    Last Post: 07-24-2002, 03:48 AM
  3. quick question
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 07-22-2002, 04:44 AM
  4. Quick Question Regarding Pointers
    By charash in forum C++ Programming
    Replies: 4
    Last Post: 05-04-2002, 11:04 AM
  5. Quick question: exit();
    By Cheeze-It in forum C Programming
    Replies: 6
    Last Post: 08-15-2001, 05:46 PM