Jump to content

C help yet again..

WorldDominator

Sorry to keep bugging everyone out there that tries to help me...I just usually have one thing about syntax or something I don't know and it throws me off. I have yet another puzzle.

 

Wow that's small. I'll try editing. Better..

 

Now my output in the top left is supposed to look like it does in the bottom left but as you can see they look nothing similar. I used the fflush(stdout); because I referenced other material that was similar to this problem and that was done before every input. It seems to make no difference if I remove it though.

 

jtrspk.png

i5 4670k | Sapphire 7950 | Kingston 120GB SSD | Seagate 1TB | G.Skill Ripjaw X Series 8GB

PB238Q | Steelseries Sensei | Ducky DK9087 | Qck Heavy

Build Log: http://linustechtips.com/main/topic/44902-from-imac-to-my-own-creation/

Link to comment
Share on other sites

Link to post
Share on other sites

You can use sites like imgur.com to post good sized pictures on the forum.

I just fixed it. I don't have an imgur account and pretty sure you need one..right?

i5 4670k | Sapphire 7950 | Kingston 120GB SSD | Seagate 1TB | G.Skill Ripjaw X Series 8GB

PB238Q | Steelseries Sensei | Ducky DK9087 | Qck Heavy

Build Log: http://linustechtips.com/main/topic/44902-from-imac-to-my-own-creation/

Link to comment
Share on other sites

Link to post
Share on other sites

I just fixed it. I don't have an imgur account and pretty sure you need one..right?

You don't need one, I use it and I don;t remember making an account

Link to comment
Share on other sites

Link to post
Share on other sites

You don't need one, I use it and I don;t remember making an account

I just fixed it. I don't have an imgur account and pretty sure you need one..right?

You'll need an account to upload pictures to your profile.

New to Star Citizen? Look no further!

Link to comment
Share on other sites

Link to post
Share on other sites

@Mac @Wauthar

 

Well the picture thing is handled lol. Do either of you know how to do any C programming? :P

 

@MikeD @random314 @Prince32780 you guys helped me on my last two. Any thoughts? 

i5 4670k | Sapphire 7950 | Kingston 120GB SSD | Seagate 1TB | G.Skill Ripjaw X Series 8GB

PB238Q | Steelseries Sensei | Ducky DK9087 | Qck Heavy

Build Log: http://linustechtips.com/main/topic/44902-from-imac-to-my-own-creation/

Link to comment
Share on other sites

Link to post
Share on other sites

@Mac @Wauthar

 

Well the picture thing is handled lol. Do either of you know how to do any C programming? :P

Sadly not, but I am on a course that teaches it... I'll help you in a years time.

Link to comment
Share on other sites

Link to post
Share on other sites

Ask @Kuzma

Main Rig: -FX8150 -32gb Kingston HyperX BLUE -120gb Kingston HyperX SSD -1TB WD Black -ASUS R9 270 DCUII OC -Corsair 300r -Full specs on Profile


Other Devices: -One Plus One 64gb Sandstone Black -Canon T5 -Moto G -Pebble Smartwatch -Nintendo 2DS -G27 Racing Wheel


#PlugYourStuff - 720penis - 1080penis - #KilledMyWife - #LinusButtPlug - #HashtagsAreALifestyle - CAR BOUGHT: 2010 Corolla

Link to comment
Share on other sites

Link to post
Share on other sites

is it good now Zoboomafoo?

I have only done c++ and a very small amount of it, sorry :(

I dont really udnerstand what you're trying to do though.

It sometihng's wrong with the number results, I find it helpful to print all of your variables at the end

Link to comment
Share on other sites

Link to post
Share on other sites

there's a /n in there creating a new line

Console optimisations and how they will effect you | The difference between AMD cores and Intel cores | Memory Bus size and how it effects your VRAM usage |
How much vram do you actually need? | APUs and the future of processing | Projects: SO - here

Intel i7 5820l @ with Corsair H110 | 32GB DDR4 RAM @ 1600Mhz | XFX Radeon R9 290 @ 1.2Ghz | Corsair 600Q | Corsair TX650 | Probably too much corsair but meh should have had a Corsair SSD and RAM | 1.3TB HDD Space | Sennheiser HD598 | Beyerdynamic Custom One Pro | Blue Snowball

Link to comment
Share on other sites

Link to post
Share on other sites

Scratch what I just said O.o , try placing a space between the %s and /n so instead of being "%s/n" so "%s /n" it seems the parser is interpreting the code as you wanting the second name on a new line

Console optimisations and how they will effect you | The difference between AMD cores and Intel cores | Memory Bus size and how it effects your VRAM usage |
How much vram do you actually need? | APUs and the future of processing | Projects: SO - here

Intel i7 5820l @ with Corsair H110 | 32GB DDR4 RAM @ 1600Mhz | XFX Radeon R9 290 @ 1.2Ghz | Corsair 600Q | Corsair TX650 | Probably too much corsair but meh should have had a Corsair SSD and RAM | 1.3TB HDD Space | Sennheiser HD598 | Beyerdynamic Custom One Pro | Blue Snowball

Link to comment
Share on other sites

Link to post
Share on other sites

Ask @Kuzma

lmfao xD was this really necessary ?! coulda warned me idk

Console optimisations and how they will effect you | The difference between AMD cores and Intel cores | Memory Bus size and how it effects your VRAM usage |
How much vram do you actually need? | APUs and the future of processing | Projects: SO - here

Intel i7 5820l @ with Corsair H110 | 32GB DDR4 RAM @ 1600Mhz | XFX Radeon R9 290 @ 1.2Ghz | Corsair 600Q | Corsair TX650 | Probably too much corsair but meh should have had a Corsair SSD and RAM | 1.3TB HDD Space | Sennheiser HD598 | Beyerdynamic Custom One Pro | Blue Snowball

Link to comment
Share on other sites

Link to post
Share on other sites

Scratch what I just said O.o , try placing a space between the %s and /n so instead of being "%s/n" so "%s /n" it seems the parser is interpreting the code as you wanting the second name on a new line

Nope :/

 

My hypothesis is that it has something to do with my inputs.

i5 4670k | Sapphire 7950 | Kingston 120GB SSD | Seagate 1TB | G.Skill Ripjaw X Series 8GB

PB238Q | Steelseries Sensei | Ducky DK9087 | Qck Heavy

Build Log: http://linustechtips.com/main/topic/44902-from-imac-to-my-own-creation/

Link to comment
Share on other sites

Link to post
Share on other sites

Just checked an verified my suspicion. The function fgets() counts newlines as valid characters and keeps them. So you'll need to find another input function that doesn't keep the newline or remove it later in the code. I don't recall a good function to suggest but it would be good for you to look on your own anyway :P . If you come up empty I can figure something out.

 

http://www.cplusplus.com/reference/cstdio/fgets/

My rig: 2600k(4.2 GHz) w/ Cooler Master hyper 212+, Gigabyte Z68-UD3H-B3, Powercolor 7870 xt(1100/1500) w/AIO mod,

8GB DDR3 1600, 120GB Kingston HyperX 3K SSD, 1TB Seagate, Antec earthwatts 430, NZXT H2

Verified max overclock, just for kicks: http://valid.canardpc.com/show_oc.php?id=2609399

Link to comment
Share on other sites

Link to post
Share on other sites

Just checked an verified my suspicion. The function fgets() counts newlines as valid characters and keeps them. So you'll need to find another input function that doesn't keep the newline or remove it later in the code. I don't recall a good function to suggest but it would be good for you to look on your own anyway :P . If you come up empty I can figure something out.

 

http://www.cplusplus.com/reference/cstdio/fgets/

My teacher said I had to use scanf() and fgets() for these. I didn't think scanf was really what I wanted to use where I have fgets.

i5 4670k | Sapphire 7950 | Kingston 120GB SSD | Seagate 1TB | G.Skill Ripjaw X Series 8GB

PB238Q | Steelseries Sensei | Ducky DK9087 | Qck Heavy

Build Log: http://linustechtips.com/main/topic/44902-from-imac-to-my-own-creation/

Link to comment
Share on other sites

Link to post
Share on other sites

I always use scanf to deal with inputs when I know exactly what they are. And you usually know what they are, even if it is just a string (which can have whatever format).

In 4 years I used fgets (or its file counterpart) maybe once or twice.

Link to comment
Share on other sites

Link to post
Share on other sites

I always use scanf to deal with inputs when I know exactly what they are. And you usually know what they are, even if it is just a string (which can have whatever format).

In 4 years I used fgets (or its file counterpart) maybe once or twice.

so just use scanf and %s? or would I use %c? Meh I guess I can use trial and error on that :D

i5 4670k | Sapphire 7950 | Kingston 120GB SSD | Seagate 1TB | G.Skill Ripjaw X Series 8GB

PB238Q | Steelseries Sensei | Ducky DK9087 | Qck Heavy

Build Log: http://linustechtips.com/main/topic/44902-from-imac-to-my-own-creation/

Link to comment
Share on other sites

Link to post
Share on other sites

It depends. Since I guess you are interested in names (char*) and grades (which appear to be doubles), it would be %s and %lf respectively.

Link to comment
Share on other sites

Link to post
Share on other sites

It depends. Since I guess you are interested in names (char*) and grades (which appear to be doubles), it would be %s and %lf respectively.

I used %s and it works. Only problem is when I hit enter at the start of a student to print the report, it enters blank lines until i type something else and hit enter:

 

 

Student 4 last name:

 

 

 

 

 

a

 

 

*** Input Report ***

 

this is what I have where it should terminate if the user inputs just an enter

 

scanf(" %s", list[n].last);

if (strlen(list[n].last) < 1{

    break;

}

i5 4670k | Sapphire 7950 | Kingston 120GB SSD | Seagate 1TB | G.Skill Ripjaw X Series 8GB

PB238Q | Steelseries Sensei | Ducky DK9087 | Qck Heavy

Build Log: http://linustechtips.com/main/topic/44902-from-imac-to-my-own-creation/

Link to comment
Share on other sites

Link to post
Share on other sites

That is because scanf does not recognize \n as a string (%s does not match \n).

I usually ask for (or the input provides) the number of records I have to parse to avoid exactly that situation.

Maybe in that particular case you want to use fgets to be able to read the newline...?!

 

Also, flush statements used to be necessary, but not anymore.

Link to comment
Share on other sites

Link to post
Share on other sites

That is because scanf does not recognize \n as a string (%s does not match \n).

I usually ask for (or the input provides) the number of records I have to parse to avoid exactly that situation.

Maybe in that particular case you want to use fgets to be able to read the newline...?!

 

Also, flush statements used to be necessary, but not anymore.

I thought so. The textbook must be outdated ^_^

i5 4670k | Sapphire 7950 | Kingston 120GB SSD | Seagate 1TB | G.Skill Ripjaw X Series 8GB

PB238Q | Steelseries Sensei | Ducky DK9087 | Qck Heavy

Build Log: http://linustechtips.com/main/topic/44902-from-imac-to-my-own-creation/

Link to comment
Share on other sites

Link to post
Share on other sites

@Mac @Wauthar

 

Well the picture thing is handled lol. Do either of you know how to do any C programming? :P

 

@MikeD @random314 @Prince32780 you guys helped me on my last two. Any thoughts? 

 

 

Confession: I don't really know how to code in C

 

I do c# and some java

[spoiler=»--((¯`·._.·¤~●oO му яιg Oo●~¤·._.·´¯))--«] Case: Corsair 600T White       CPU: Core i7 3930k @ 4.3GHz                     SSD: Crucial M500 480GB

MB:    Asus P9X79 LE         GPU: Nvidia GTX 780 Reference             HDD: WD Caviar Green 3TB

PSU:   Seasonic X-1050      RAM: G.Skill Trident X 32GB @ 2.4GHz   ☃ There are 10 types of people in this world. Those who understand binary and those who don't.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×