Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 6th, 2006, 8:02 PM   #51
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
If you upgrade a dummies book, is it still a dummies book???
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jul 7th, 2006, 2:33 AM   #52
thondal
Programmer
 
thondal's Avatar
 
Join Date: Jan 2006
Location: Norway
Posts: 80
Rep Power: 3 thondal is on a distinguished road
Send a message via MSN to thondal
Quote:
Originally Posted by Arevos
fgets allows you to specify a limit to prevent this type of vulnerability:
char buffer[10];
fgets(buffer, 10, stdin);
fgets can get information from any stream, such as from a file. The stdin stream represents the standard user input into a program.
Wow, I actually understood that!

Okey, i'll do some more coding and then i'll se what the result looks like. I'm not sure if I can get a newer version of the dummies book. The library is kinda slow taking in programming books.

funny dawei haha

-thondal-
__________________
"die" he screamed at the polygon man. When he was done with him, only four points remained, a quad of what he once was.
thondal is offline   Reply With Quote
Old Jul 7th, 2006, 3:23 AM   #53
thondal
Programmer
 
thondal's Avatar
 
Join Date: Jan 2006
Location: Norway
Posts: 80
Rep Power: 3 thondal is on a distinguished road
Send a message via MSN to thondal
DOH!
I just got word from my boss that I'm not allowed to have a compiler on the work-machine that i'm on. He said that when I get my laptop I can do it, but not on this machine... I'm not getting my laptop before 25th of july, because it's a special order, a mix between macintosh and windows and the colour he ordered for me was out. DOH!

-thondal-
__________________
"die" he screamed at the polygon man. When he was done with him, only four points remained, a quad of what he once was.
thondal is offline   Reply With Quote
Old Jul 7th, 2006, 3:33 AM   #54
uman
Expert Programmer
 
Join Date: Dec 2004
Posts: 794
Rep Power: 4 uman is on a distinguished road
A mix between Mac and Windows?!

By the way, if you're work is unrelated to programming, wouldn't your boss have gotten mad at you for using company time to program on the work computer? I hope you weren't badly scolded.
__________________
Few people deserve to be compared to (Rush) Limbaugh, most of them were convicted at the Nuremburg trials.
--WilliamSChips on Slashdot
uman is offline   Reply With Quote
Old Jul 7th, 2006, 3:42 AM   #55
thondal
Programmer
 
thondal's Avatar
 
Join Date: Jan 2006
Location: Norway
Posts: 80
Rep Power: 3 thondal is on a distinguished road
Send a message via MSN to thondal
Quote:
Originally Posted by uman
A mix between Mac and Windows?!
Yes... don't know how. I guess it's running dual OS. It's apple machine, so at least it's not microsoft's idea

Quote:
By the way, if you're work is unrelated to programming, wouldn't your boss have gotten mad at you for using company time to program on the work computer? I hope you weren't badly scolded.
My work is actually is a network and computer admin which controls about 5-10 000 machines. So.... but right now I'm at the reseption ( I think that's the word for it) as a summer-job, to learn the names of people and stuff. I don't start with computers before 16th august.

GO NOTEPAD!

By the way is there a way to compile it yourself?

-thondal-
__________________
"die" he screamed at the polygon man. When he was done with him, only four points remained, a quad of what he once was.
thondal is offline   Reply With Quote
Old Jul 7th, 2006, 12:39 PM   #56
thondal
Programmer
 
thondal's Avatar
 
Join Date: Jan 2006
Location: Norway
Posts: 80
Rep Power: 3 thondal is on a distinguished road
Send a message via MSN to thondal
hey dawei, having some problems. When using fgets, how do i put them in my text so they turn out okey in the output... i got this:

#include <stdio.h>

/* Welcome to Lands End version 0.03.
Author: Simen Skogheim
Copyright: Magical Pictures
Last edited: 7/7 - 2006
 */


int main()
{
    char name[25];
    char race[15];
    char sex[8];
    char proffesion[15];
    char answer[5];
    
    printf("Welcome to \"Lands End\" rpg game.\n\nTake on the role as a Hero    in an ever growing world,\nwhere you can decide the fate of the world you are in.\n");
    gets(answer);
    printf("The God \"...\" has given you life.\nUse it to promote goodness in this world, be neutral or aid the darkness.\n");
    printf("First, what is the name you whish to be known by?\n");
    fgets(name, 25, stdin);
    printf("Are you Male or Female?\n");
    fgets(sex, 8, stdin);
    printf("Are you an Elf or Human?\n");
    fgets(race, 15, stdin);
    printf("Are you, a fighter, mage or ranger?\n");
    fgets(proffesion, 15, stdin);
    printf("\n\nWelcome to \"Lands end\" %s,\nYou enter this world as a %s %s, and belong to the race of %s.\nYour powers grow as you train, use them wisely...\n",name,sex,proffesion,race);
    gets(answer);
    printf("\n\nFirst all you see is a bright shining light. Then everything turns dark. \n\nYou can feel your body, but it feels to heavy to move.\nThen, you hear a sound in the distance, almost like mumbling.\nYou concentrate and try to make out the words \n\n");
    gets(answer);
    printf("\"Hey, are you okey?\" \n\"Can you hear me?\"");
    printf("\n\nYou open your eyes and can faintly make out the face of what looks like a %s,\nstanding next to you.",race);
    getchar();
    return(0);
}

but my output on the last gets all wrong... is it the use of the %s? If you can point me to where my mistake is, then I would appreciate it... You don't have to tell what the problem is, just where, I want to fix it myself (helps me learn i guess)

-thondal-
__________________
"die" he screamed at the polygon man. When he was done with him, only four points remained, a quad of what he once was.
thondal is offline   Reply With Quote
Old Jul 7th, 2006, 1:27 PM   #57
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Well, for one thing, you're still using 'gets'. Slap your own wrist. Toss it in the shit can. Forget you ever heard of it. Secondly, you use it twice in a row for 'answer', which overwrites the previous 'answer', without (apparently) having used it. Thirdly, you don't really describe your failure, just that you have one "on the last gets". Information is key, both in debugging and in eliciting effective answers. It would also be less strenuous on your potential respondents if you didn't require them to scroll from El Paso to Cincinnati to see what variables you are using in your 'printf'. Make a simple example that demonstrates the problem. In other words, shorten that blabber until you have resolved the problem.

Replace the 'gets' with 'fgets', double check your usage of each item, post back with problems.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jul 7th, 2006, 4:09 PM   #58
thondal
Programmer
 
thondal's Avatar
 
Join Date: Jan 2006
Location: Norway
Posts: 80
Rep Power: 3 thondal is on a distinguished road
Send a message via MSN to thondal
okey here's where the problem lie I guess

    printf("\n\nWelcome to \"Lands end\" %s,\nYou enter this world as a %s %s, and belong to the race of %s.\nYour powers grow as you train, use them wisely...\n",name,sex,proffesion,race);

the output is as follows

welcome to "lands end" thondal
,
you enter this world as a male
mage
, and bleong to the race of elf
.
your powers grow as you train, use them wisely


kinda frustrating...

-thondal-
__________________
"die" he screamed at the polygon man. When he was done with him, only four points remained, a quad of what he once was.
thondal is offline   Reply With Quote
Old Jul 7th, 2006, 4:42 PM   #59
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Come on, man. You show a statement, you say the output is thus and such, but not what it's supposed to be. We can't see what you typed for input. You don't show your rewritten code. Nevertheless, my crystal ball says that what you have is newlines in your input that you didn't remove. Those come from the ENTER key. Some people want them. Fgets reads until the end of file, until the specified maximum number of characters are read, or until it finds a newline. It then terminates the buffer with '\0'. If it maxes out on characters, there won't be a newline. If there's a newline, it'll be the last character in your buffer, at strlen [buffer] - 1. Dump a '\0' there if you want to get rid of it. Man 'fgets'. There's a plethora of information there; all one has to do is read. It also tells you how an error is indicated; don't forget to check.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jul 8th, 2006, 3:31 AM   #60
omgpix
Newbie
 
Join Date: Jun 2006
Location: Vancouver, BC.
Posts: 2
Rep Power: 0 omgpix is on a distinguished road
Yeah, yeah, so it's so long past the recommendation of material stage, still.

http://www.eskimo.com/~scs/cclass/notes/sx11a.html
http://www.crasseux.com/books/ctutorial/

Those two + whatever x terminal (konsole ftw) + vim + gcc got me where I am today. I find books alright when I'm interested in something specific, but when you want to learn how to code or any such thing, they're far too cumbersome. At least for me.

Open a terminal, attempt to compile your program, watch it fail, figure out why.
Of course, after growing in such an evironment I now find it completely unnatural/limiting to write / compile anything on a non-*nix platform So it's not without its pitfalls.

The fault of most online tutorials is they tell you how to do _x but don't even come close to explaining how it works.

http://www.eskimo.com/~scs/cclass/ <-- is the most detailed tutorial/course/whatever I've ever found. Check out http://www.eskimo.com/~scs/cclass/notes/sx11a.html to get a guess of the quality.

The was also a very humourous article written on pointers, in story form. I wish I could remember the URL.
omgpix is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:10 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC