Problem with files in C

This is a discussion on Problem with files in C within the C Programming forums, part of the General Programming Boards category; Hi.. I'm new here and i would be very happy if someone answer this I have a this problem: Make ...

  1. #1
    Registered User
    Join Date
    Dec 2012
    Posts
    1

    Problem with files in C

    Hi.. I'm new here and i would be very happy if someone answer this
    I have a this problem:
    Make program which will make two new files: letter.txt which would include only letters and numbers.txt which would include only numbers. The primary file should content this text: Ova e 1pos56ledn7ata labo7rat8oriska vezba 93po1 pr84edm5et0ot Strukturirano 569 prog12ram4ira5nje. Se2 na1deva2me deka bese 358 in197tere8sno pi1su59vanje3to na pro22gra3mi3 vo C.
    ATTENTION: some of the words might content only numbers or only letters.
    for example: 1pos56ledn7ata--> 1567 in numbers.txt, poslednata in letters.txt

    Thank you in adition.

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    5,827
    Read this link.
    Right 98% of the time, and don't care about the other 3%.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,333
    A development process
    Start with a program which simply copies input.txt to output.txt one character at a time.

    When you can do that, it's not too hard to be able to write characters to two different files, based on some test of the character.
    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.

  4. #4
    Registered User
    Join Date
    Nov 2012
    Posts
    978
    Write it as pseudocode first

    Read one character c
    Is c a letter? If so, write it out to "letters.txt"
    Is c a number? If so, write it out to "numbers.txt"
    Is c a space? If so, do nothing.
    Is c something else? Exit program with error message "INVALID INPUT: Must contain only letters, numbers and spaces"

    Next try to find out how exactly to do each thing required... "how do I read a character?", "how do I tell if c is a letter", and so on... This method works in any programming language.

  5. #5
    Registered User
    Join Date
    May 2012
    Posts
    331
    The functions you need are fopen(), fclose(), fgetc(), fputc(), isalpha() and isdigit().
    You'll need to look these up, and work out the logic yourself.
    I'm the author of MiniBasic: How to write a script interpreter and Basic Algorithms
    Visit my website for lots of associated C programming resources.
    http://www.malcolmmclean.site11.com/www

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. still a problem with txt files
    By Makaila in forum C++ Programming
    Replies: 3
    Last Post: 01-18-2010, 01:11 AM
  2. Files problem
    By Signpost in forum C Programming
    Replies: 10
    Last Post: 11-29-2007, 02:23 AM
  3. Problem with .cfg files
    By ShadowIII in forum C++ Programming
    Replies: 3
    Last Post: 11-29-2004, 05:52 PM
  4. problem with .avi files
    By Silvercord in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 01-18-2003, 10:41 PM
  5. I have a problem if FILEs
    By talal*c in forum C Programming
    Replies: 22
    Last Post: 01-07-2002, 04:56 AM

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