Read in multiple integer arrays from one file

前端 未结 2 1613
醉酒成梦
醉酒成梦 2021-01-28 08:12

I have a problem where I need to read in multiple arrays from a .txt file and output the maximum sum subarray. Here is the text file:

[1, 4, -9, 8, 1, 3, 3, 1, -         


        
2条回答
  •  暖寄归人
    2021-01-28 09:02

    Read in the file with fread calls into a buffer. Explode buffer per line (\n) / array. (Count how many arrays do you need and prepare.) Explode lines per numbers - separator: comma and space. (Count length of array and allocate.) Numbers would contain sign and digits. Assuming digits are contiguous in range '0'..'9', '0'+digit gives the value of the digit. Value of the number can be calculated from sign, digit values and their order.

提交回复
热议问题