Thread: C Homework

  1. #1
    Registered User
    Join Date
    Jun 2019
    Posts
    2

    Post C Homework

    Please can someone help me doing this program?
    1.- Read a text file
    2.- Convert the readed text file into array.
    3.- That array split it into another small arrays, every n(sizes).
    Ex:
    [help me] split it in every 3 chars = [hel] [p m] [exx]

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    So break the problem down into steps.

    Start by just reading the file in, and printing it out again.
    Code:
    int main ( ) {
        char buff[BUFSIZ];
        while ( fgets(buff,BUFSIZ,stdin) != NULL ) {
            fputs(buff,stdout);
        }
        return 0;
    }
    Replace stdin and/or stdout with your file handle(s) opened using fopen.
    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
    Registered User
    Join Date
    Jun 2019
    Posts
    2
    So with fgets, you are getting every single character one by one?

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    fgets = file get string.

    It fetches a whole line, up to the first newline / full buffer / end of file (whichever comes first).

    Your first action on seeing a function() you've never seen before is to type into google "man function" and do some reading.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. homework help Please!
    By hnparmar in forum C Programming
    Replies: 2
    Last Post: 03-10-2013, 04:18 PM
  2. C homework help
    By camel-man in forum C Programming
    Replies: 6
    Last Post: 01-25-2011, 09:19 AM
  3. Please help me with my c++ homework!
    By dmeyers81 in forum C++ Programming
    Replies: 35
    Last Post: 11-04-2010, 07:47 AM
  4. Homework Help
    By alecmcraig in forum C Programming
    Replies: 4
    Last Post: 11-17-2007, 01:03 AM
  5. Homework =)
    By Raeliean in forum C++ Programming
    Replies: 9
    Last Post: 07-16-2005, 10:27 PM

Tags for this Thread