I need help with this code

This is a discussion on I need help with this code within the C Programming forums, part of the General Programming Boards category; The code is supposed to define a file pointer called "fpwrite" open a text file called "sppdata.txt" and check to ...

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    2

    I need help with this code

    The code is supposed to define a file pointer called "fpwrite"
    open a text file called "sppdata.txt"
    and check to see if the file is opened and use it to write "Hello Sara" a hundred times. I am missing a couple of things I think.
    Attached Files Attached Files

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    You're missing a for loop which loops 100 times, and a fprintf() call inside that loop
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Nov 2003
    Posts
    46
    Code:
    #include<stdio.h>
    #include<string.h>
    
    int main(void)
    {
    
        char name[31] = "Hello Teri";
        FILE *fpwrite;
        int i;
        
        fpwrite=fopen("cppdata.txt" , "w");
        
        if (fpwrite==NULL)
        {
            printf("cannot open or create file.\n");
        }
        else
        {
    
            for (i=0;i<100;i++)
            {
                fprintf(fpwrite,"%s\n",name);
            }
            fclose(fpwrite);
    
        }    
    
        return 0;
    
    } /*main*/

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 08:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 03:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 05:05 PM

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