[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Hi g I was just wondering how to do this because it's killing

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 12
Thread images: 2

File: circut.png (36KB, 1105x585px) Image search: [Google]
circut.png
36KB, 1105x585px
Hi g

I was just wondering how to do this because it's killing me.

In the "C" Language

With fscanf how can you possibly take a text file with the contents:

"a b 10 20 30 67
a b 20 30 77 64"


Where "a" and "b" are names and the numbers at the end have no limit to how many?

So that you can have a variable to store each name and each of the numbers?

fscanf("%s %s %d etc.") does not work because there is two lines
>>
install BString (better string library)
read in the file as a bstring
split the bstring by the newline character
use fscanf on each line
>>
If the count of numbers is variable, you can't really do it with fscanf, unless you define a maximum count of numbers. Functions that deal with formatted text typically return the number of elements that matched the template string. You can use that number to determine how many numbers you parsed. But this is still a fixed approach. For a better approach, consider parsing the lines yourself, which is easy if you use strtok.
>>
>>51478978
Or just use fgets? What the fuck is wrong with millennial programmers, shit son.
>>
>>51478880

while ( fscanf("%s %s %d %d %d %d",a, b, &c, &d, &e, &f) == 6) {
// stuff here
}

>>
>>51479037
You're just missing the read line-by-line code
>>
>>51479037
so what if you don't know how many numbers at the end there are and it isn't just 4 %d's

Each newline there is a different number e.g.

Pretend the file is:

"string string num num num
string string num num
string string
string string num num num num num num"

but you don't know what the file looks like or how many of each thing there is except two strings.

But there can't be more than 10 on any line
>>
File: 3678.deprecated.png (151KB, 1000x379px) Image search: [Google]
3678.deprecated.png
151KB, 1000x379px
>>51479007
>fgets
>>
>>51479119
>Pretend the file is:
>"string string num num num
>string string num num
>string string
>string string num num num num num num"

OP said
>With fscanf how can you possibly take a text file with the contents:
>
>"a b 10 20 30 67
>a b 20 30 77 64"

so i assumed the file was that
>>
>>51479119
Change the condition to (> 2) and use the return value to determine how many numbers you parsed (matches - 2).
>>
>>51479148
sorry but how would you do it assuming you don't know what the file is.

Also there are multiple lines of text as shown in the "pretend" example.
>>
>>51479123

You are mistaken.

gets is deprecated
fgets is not deprecated as of C11.
Thread posts: 12
Thread images: 2


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.