![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Apr 2006
Posts: 3
Rep Power: 0
![]() |
simple fputs question.
Gooday
A real beginner of c. So hope to get some help. here goes If user key in "5" create a file name "raw.txt" prompt user to key in "A" or "B". Example is "A" is selected. raw.txt inside must reflect "a" if user then select "B" raw.txt must reflect "b" on newline. :banana: |
|
|
|
|
|
#2 |
|
Professional Programmer
|
This is not that hard. Use some if/else statements in your code for controlling user input.
Check this out for fputs(); http://irc.essex.ac.uk/www.iota-six....putc_fputs.asp Please consider reading the "How to post a question" thread. Thank you.
__________________
The world's first athletic computer geek! The home of PrProgramsStudios How not to post a question: <-- Please don't reply |
|
|
|
|
|
#3 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
@Prm753: Using gets, is a very bad idea.
@OP: Welcome to the forums, please read the "How to post a question" thread at the top of the C/C++ forum. A quick question: Why are you beginning with C instead of C++? Anyway, here's some code, if you don't understand it read your man pages, manual or search for the functions on internet, you can find them here. If you do want to use C++, you can find a tutorial here, the stuff on pointers isn't exactly good or accurate last time I checked, but you can find that in DaWei's profile. #include <stdio.h>
int main()
{
int i = 0, gotit = 0;
char c = 0;
FILE * fp;
do
{
printf("Enter number 5: ");
gotit = scanf ("%d", &i);
rewind(stdin);
}
while((gotit != 1) || (i != 5));
if((fp = fopen("raw.txt", "wb")) == NULL)
{
fprintf(stderr, "Cannot create/open file\n");
return 1;
}
do
{
printf("Enter 'A' or 'B' (capital letters): ");
gotit = scanf ("%c", &c);
rewind(stdin);
}
while((gotit != 1) || ((c != 'A') && (c != 'B')));
if(c == 'A')
fputs("a", fp);
else
fputs("b", fp);
return 0;
}
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
|
#4 |
|
Newbie
Join Date: Apr 2006
Posts: 3
Rep Power: 0
![]() |
Nnixonnnnnn...................
Hey NNIXON REAL THANKS
i still have the last part. Hope you can you help. Big Thankyou!!!!!! PART A (You have solved!) :banana: If user key in "5" create a file name "raw.txt" prompt user to select "A" or "B". Example is "A" is selected. raw.txt inside must reflect "a" if user then select "B" raw.txt must reflect "b" on newline. PART B (Hope you could help! Thanks) now we have either "a\n, b\n" or "b\n,a\n" in raw.txt compare with "match.txt" In "match.txt" it will indicate rules. If "a\n, b\n" print "Apple Pie" or "b\n, a\n" print "Chicken Pie" print the results |
|
|
|
|
|
#5 |
|
Newbie
Join Date: Apr 2006
Posts: 3
Rep Power: 0
![]() |
By the way I am learning C. not C++...
|
|
|
|
|
|
#6 |
|
Professional Programmer
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4
![]() |
Is it some homework assignment?
__________________
PFO - My daily dose of technology. |
|
|
|
|
|
#7 | |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
Quote:
Why not C++? C is OLD. :pYou can read the file. (Hint: use fscanf or fgets.)
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
|
|
#8 | |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Quote:
__________________
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 |
|
|
|
|
|
|
#9 | |
|
Expert Programmer
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4
![]() |
Quote:
Did I mention he is 66+ years old. I'm sure PL/I was pretty fly when he was in college. |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|