gorpe
gorpe

Reputation: 25

quote by placing > at start of line in python?

I need to do a or linebreak add 2 spaces at end

Upvotes: 0

Views: 67

Answers (2)

Laughing_Man
Laughing_Man

Reputation: 179

Another solution is some kind of a trick without using realloc(). You can read your file twice.

  1. Open a file
  2. Iterate through its content and find a size of the future array
  3. Close your file
  4. Allocate memory
  5. Open a file again
  6. Read numbers from the file and fill your array

P.S. In the future, try to be more specific while writing questions titles.

Upvotes: 1

Gal Birka
Gal Birka

Reputation: 591

You need to use some sort of Realloc() function. This function is used to extend the allocated size. The program should be something like that:

  1. Allocate default value with malloc.
  2. Read next number from your input.
  3. If you got the number and this is not EOF (End of file), then use realloc to extend the allocated size by 1 and put the new number at the end.
  4. Keep doing this untill you reach EOF.

Of course this is just one solution, and there may be others.

Upvotes: 1

Related Questions