Thread: Beginner in C

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    13

    Question Beginner in C

    Hello,

    I have to get 200'000 words in an array.

    I use

    Code:
    fscanf(ptr1,"%s", words[i]);
    I have one problem... It crashing because of the stack size.

    I read about the function malloc, but I didn't figured how to use it to make it work yet...

    I could use some help plz

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    So are the number of words, and the maximum length of each word known for this problem?

    Or are you expected to be able to deal with any number of words with any length?
    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
    Mar 2012
    Posts
    13
    Quote Originally Posted by Salem View Post
    So are the number of words, and the maximum length of each word known for this problem?

    Or are you expected to be able to deal with any number of words with any length?
    I can deal with any number of words with any length, but I need to get all those words in the array

  4. #4
    Registered User
    Join Date
    Mar 2012
    Posts
    13
    I think i found it

    If I do words = malloc(2000000*sizeof(words));

    It should work I guess

    words is defined as in the function

    int chargeWords(char *fileName, Word words[MAXNBWORDS], int lenghts[MAXNBWORDS], int *err)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C Beginner - Need Help
    By .C-Man. in forum C Programming
    Replies: 8
    Last Post: 10-13-2010, 04:19 PM
  2. C++ Beginner Help On XP
    By rayne117 in forum C++ Programming
    Replies: 7
    Last Post: 01-07-2009, 01:45 PM
  3. Windows programming for beginner (Absolute beginner)
    By WDT in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2004, 11:21 AM
  4. beginner ?
    By braincrash in forum C Programming
    Replies: 2
    Last Post: 02-18-2003, 03:33 AM