The best way to deal with user input (in respect to error checking, validation, recovery) is to read full lines with fgets(), then parse those lines with sscanf().
This requires a bit more work than...
Type: Posts; User: qny
The best way to deal with user input (in respect to error checking, validation, recovery) is to read full lines with fgets(), then parse those lines with sscanf().
This requires a bit more work than...
scanf() (line 29) leaves the ENTER in the input buffer.
fgets() (line 34) reads that ENTER to the first position in str.
The subsequent test fails.
Do not mix scanf() and fgets().
Ignore the...
Please consider using SQLite as a replacement for flat files -- according to their own documentation SQLite was designed to replace fopen(), fread(), fwrite(), fclose(); not to replace Oracle.
If...
1. Yes, it produces UB. You try to put more characters in str1 than there is space for. str1 has space for 5 characters and the zero terminator, you try to put 31 and the zero terminator in that...
You want to have a loop where you read the data from the file.
basically:
/* pseudo code */
fopen();
some_kind_of_loop {
/* readdata */
/* printdata */
}
fclose();
Where is pFile referenced in your program? ???
Let's see:
line 5: ok, declare the variable
line 8: ok (kinda -- you missed testing for errors), open the file for reading
line 9: ok (kinda --...
Why do you remove 1 from num_employees in line 12?
Without that, the for loop executes one less time than required (and the array size is too short).
Please, please, please ... learn to use arrays!
#include <stdio.h>
int main(void) {
int input, i;
const char *station[] = {
"Ashford Station", "Brentworth Station",...
If the user types "<SPACE> <4> <2> <SPACE> <ENTER>" this will not consume the <ENTER>.
syntax error on line 12 ...
if you meant that to be a for and are ussing a C89 compiler: no return from main.
Also the cast to the return value of malloc is redundant. You don't check for...
If you don't need tight control, try atoi().
If you want tighter control of errors, prefer strtol().
Read the function descriptions!!!
char input1[] = "-c123";
char input2[] = "-c 123";...
Unlike "proper string functions" they also work with non null-terminated char arrays.
char a[12] = "not a string";
char b[18] = "another non-string";
char c[] =...
No, getchar() reads a single character. What you can do with getchar(), is manage the input little by little and build larger parts as you go along. Remember to properly terminate the strings!
...
Despite their names, strncpy() and strncat() were not designed to be used with strings.
I suggest you do not use them.
Also your string delimiters are not part of the Basic character set and are...
I did offer a suggestion with an edit. Maybe you didn't see it.
Do not mix scanf() and other input functions.
Best way (the one with most control) is to read lines with fgets() and then deal with...
Please explain line 17.
row+= (row-1);
Why do you want to change the value held by `rows`?
What do you want to achieve with it?
EDIT: Never mind the above
Don't mix scanf() and other...
It could print 7 6 8
it could print yellow
it could format your hard drive
it could send money from your bank account to mine
Don't write Undefined Behaviour!
To see what your compiler, with...
The order in which the program executes the parameters to a function is unspecified.
Relying on a specific order is Undefined Behaviour.
Don't rely on specific order.
Don't write code with...
Unix-like OSes treat text mode files and binary mode files the exact same way.
Using binary mode when not dealing with text is, nevertheless, a good idea TM no matter the OS in use.
Instead of looking at the file with a text editor, try a hex editor.
With a different indentation (more like what the program does) your program looks like this:
int main ()
{
int days, pennies;
{
printf ("days of month: ");
Just rename main() ...
int my_defined_function(){
/* YOUR EXACT CODE AS ABOVE */
}
and add a different main that calls your function
Basically change the vector/linked list before you call the recursive function and change it back afterwards.
When the recursive function reaches the base case, just print the result (or save it in...
Use recursion ...
The sets of 5 numbers (1 to 9) that add up to 28 include:
: the number 1 plus the sets of 4 numbers (2 to 9) that add up to 27
: the number 2 plus the sets of 4 numbers (3 to...
You need to initialize wklyWage (to 0).