Like "Rob Willams"
this is what I have
char Employee1 [60];
Like "Rob Willams"
this is what I have
char Employee1 [60];
Last edited by Demipimp; 12-05-2008 at 12:36 AM. Reason: I messed up
Several ways. Through an initialization statement, or via a built-in function like strcpy().
Mainframe assembler programmer by trade. C coder when I can.
By using scanf I'm putting in information for a pay roll
I'm not going there. I smell a snowball.
Post your complete question. I'm not going to be sucked into a 20-questions one-at-a-time thread.
Mainframe assembler programmer by trade. C coder when I can.
your right sorry repost an a decent question now
fgets(employee1,sizeof(employee1),stdin);
employee1[strlen(employee1)-1]='\0'; //To trim off newline character
i dunno if that answers your question
>//To trim off newline character
Or whatever else is there if fgets terminates by filling up the buffer instead of finding a newline. This is a subtle bug. You need to guarantee that you're trimming the right character, or do nothing. For example using strlen:
The most common method is with strchr:Code:size_t len = strlen ( Employee1 ); if ( len > 0 && Employee1[len - 1] == '\n' ) Employee1[len - 1] = '\0';
Some more exotic ones you'll see are strtok and strcspn:Code:char *newline = strchr ( Employee1, '\n' ); if ( newline != NULL ) *newline = '\0';
Code:strtok ( Employee1, "\n" );Code:Employee1[strcspn ( Employee1, "\n")] = '\0';
My best code is written with the delete key.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
The problem I have with MK27's answer is that if most software used this method I would never receive mail for "Matt7ew" or any other fun alphanumeric names that I commonly get. And I am sorry, sir, but I cannot imagine a world without such things.