Simple Scanf question for beginner

This is a discussion on Simple Scanf question for beginner within the C Programming forums, part of the General Programming Boards category; So Im back to programming in C after a long Python hiatus, and boy is it a lil rough going ...

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    41

    Simple Scanf question for beginner

    So Im back to programming in C after a long Python hiatus, and boy is it a lil rough going from one to the other.

    anyways im taking in an input file that will always have 2 columns of numbers, something like this:

    2.31 32.1
    7.52 54.2
    21.12 1.2

    i want to scan in the first number as a variable X and the second as a variable Y then they will be added to a dynamic array blah blah blah, that all works.

    this is what I am doing and it causes a seg fault:
    a = fscanf(inputFile, "%f%*[\t]%f", X,Y);

    just doing fscanf(inputFile, "%f", X); worked nicely on getting the first number, but i want to get the second in the same line so I can turn it into a while loop.

    any help is appreciated greatly

  2. #2
    Registered User
    Join Date
    Mar 2009
    Posts
    399
    If X and Y are floats then you should pass their addresses to fscanf, not their values.

    Code:
    fscanf(inputfile, "%f %f", &X, &Y);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about scanf and spaces or whitespace
    By jensbodal in forum C Programming
    Replies: 4
    Last Post: 11-26-2009, 03:12 PM
  2. Simple question regarding variables
    By Flakster in forum C++ Programming
    Replies: 10
    Last Post: 05-18-2005, 08:10 PM
  3. Simple class question
    By 99atlantic in forum C++ Programming
    Replies: 6
    Last Post: 04-20-2005, 11:41 PM
  4. Simple question about pausing program
    By Noid in forum C Programming
    Replies: 14
    Last Post: 04-02-2005, 08:46 AM
  5. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM

Tags for this Thread


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