Thread: format in Fortran

  1. #1
    Registered User
    Join Date
    May 2006

    format in Fortran

    I need to know is there any equivalent of the "format" statement used in Fortran77 in C. For example what would be the equivalent of the following statement in C (How is format used in the line with 200?)
    Program contbc

    parameter (ndwgt=1000,ndpow=1000)

    dimension cplot(ndwgt,ndpow)

    character*80 project_name
    character*80 control_file

    x status="old")

    200 format(a)
    read(10,200) project_name
    write(6,200) project_name
    read(10,200) control_file
    write(6,200) control_file

    read(10,*) nwgt_start,nwgt_end,nwgt_step
    write(6,*) nwgt_start,nwgt_end,nwgt_step
    read(10,*) pow_start,pow_end,pow_step
    write(6,*) pow_start,pow_end,pow_step


  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    I can't be bothered to google for a definition of what format does in Fortran.
    Perhaps you could inform us of what it does, then perhaps we can tell you how to do that in C
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Join Date
    Aug 2005

  4. #4
    Been here, done that.
    Join Date
    May 2003
    printf() or fprintf() -- it's a combination of WRITE/FORMAT

    scanf() or fscanf() -- it's a combination of READ/FORMAT
    although a combination of fgets()/sscanf() would be better.

    int main()
    //      character*80 project_name
    //      character*80 control_file
        char project_name[80];
        char control_file[80];
        char tmpbuf[80];
        int nwgt_start, nwgt_end, nwgt_step;
        int pow_start,pow_end,pow_step;
        FILE *st;                // define your I/O or FILE channel == 10
    //  open(10,file="setup.dat",form="formatted", status="old")
        st = fopen("setup.dat", st);
    //  200 format(a)
    //  read(10,200) project_name
        fgets(project_name, 80, st);
    //  write(6,200) project_name
        printf("%s", project_name);   // printf=to screen=6, %s="a format"
    //  read(10,200) control_file
        fgets(control_file, 80, st);
    //  write(6,200) control_file
        printf("%s", control_file);
    //  read(10,*) nwgt_start,nwgt_end,nwgt_step
        fgets(tmpbuf, 80, st);      // Read the line of ints.  %d = int conversion
        sscanf(tmpbuf, "%d %d %d", &nwgt_start, &nwgt_end, &nwgt_step);
    //  write(6,*) nwgt_start,nwgt_end,nwgt_step
        printf("%d %d %d", nwgt_start, nwgt_end, nwgt_step);
    //  read(10,*) pow_start,pow_end,pow_step
        fgets(tmpbuf, 80, st);      // Read the line of ints.  %d = int conversion
        sscanf(tmpbuf, "%d %d %d", &pow_start, &pow_end, &pow_step);
    //  write(6,*) pow_start,pow_end,pow_step
        printf("%d %d %d", pow_start,pow_end,pow_step);
    //  close(10)
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. real-world apps in C++ (preferably simple)?
    By Aisthesis in forum C++ Programming
    Replies: 13
    Last Post: 06-12-2009, 02:03 PM
  2. GradeInfo
    By kirksson in forum C Programming
    Replies: 23
    Last Post: 07-16-2008, 04:27 PM
  3. function returning hour in either 12 or 24 hour format
    By stanlvw in forum C Programming
    Replies: 4
    Last Post: 01-01-2008, 06:02 AM
  4. Compression/Decompression Wave File and MP3
    By cindy_16051988 in forum Projects and Job Recruitment
    Replies: 51
    Last Post: 04-29-2006, 07:25 AM
  5. Seeking Format Advice
    By PsychoBrat in forum Game Programming
    Replies: 3
    Last Post: 10-05-2005, 06:41 AM
Website Security Test