Rooted OnePlus 2 64GB Ed, Android 5.1.1 OxygenOS ; on teifin' AT&T's network; Rooted ASUS Transformer TF101 w/ dock, Android 5.1 KatKiss; Laptop: ASUS X550C, 2.0GHzx2, 8GB, 512GB SSD, Kubuntu 15.10;
Facebook page: Skeleville Technology Solutions
Guess I'll use
unless someone has something better.Code:printf("Please enter the First name then Surname name of a student.\n"); scanf("%s%s", &name, &name1);
Project > http://naturaldisastertips.com
You could also look at the gets() function. I do recall hearing that it is not recommended but it works.
http://www.cplusplus.com/reference/c...y/cstdio/gets/
3.14159265358979323846264338327950288
4197169399375105820974944592307816406
28620899862803482534211706798 pi 101
Having a problem with this loop..
I need it to check for a file if the file doesn't exist it prompts the user to enter the name of the file they want to read until they enter the right file name
Currently usingCode:int read() { char filename1[50]; printf("Please Enter the name of the child whos report you would like to view.\nNo spaces between the names & This is case sensitive\n\nExample : RicardoMcdonald\n"); scanf("%s", &filename1); strcat(&filename1, ".txt"); FILE *fp=fopen(filename1, "r"); while(fp==NULL){ system("CLS"); printf("There is no report on the student entered\n\n"); printf("Please Enter the name of the child whos report you would like to view.\nNo spaces between the names, This is case sensitive\n\nExample : RicardoMcdonald\n"); scanf("%s", &filename1); FILE *fp=fopen(filename1, "r"); strcat(&filename1, ".txt"); } system("CLS"); printf("File has been found"); system(&filename1); printf("File has been sucessfully open\n"); fclose(fp); retmenu(); }
Should i just stick with what I'm using currently? returning to the main menu would give the option to get back into this menu.Code:int read() { char filename1[50], namee[10000]; FILE *fpp; fpp=fopen("C:\\reportscreated.txt", "r"); if(fpp == NULL) { printf("I'm sorry but for an unknown reason the text file which stores the names was not created\n"); }else{ while(fgets(namee,10000,fpp)!=NULL); { printf("%s", namee); } printf("\n"); } printf("Please Enter the name of the child whos report you would like to view.\nNo spaces between the names & This is case sensitive\n\nExample : RicardoMcdonald\n"); scanf("%s", &filename1); strcat(&filename1, ".txt"); FILE *fp=fopen(filename1, "r"); if(fp==NULL) { system("CLS"); printf("Please try again, You will now be returned to the main menu.\n\n"); error(); } while(fp!=NULL){ system("CLS"); fclose(fp); printf("File has been found\nFile has been sucessfully open\nWhen done viewing file please close it to return to main menu\n"); system(&filename1); retmenu(); } } int error() { printf("There has been an error!!\n"); retmenu(); }
Also how can i display things from a text file I have a list of names i would like to display and
Only displays the last name on the list only.Code:while((fgets(name ,500, fpp)!=NULL);
Last edited by RickyRudy; Jan 21, 2010 at 09:30 PM.
Project > http://naturaldisastertips.com
First, there's at least one bug in the first code section. Check your pointer declarations . Next, there's alot of redundancy in that same first section. I suggest you use a do...while instead of repeating the same process outside and inside the loop. BTW, I'm loving how you unconditionally force people into entering a name . Finally, could you please properly indent your code? It'd make it so much easier to read. Both for you and us ...
Rooted OnePlus 2 64GB Ed, Android 5.1.1 OxygenOS ; on teifin' AT&T's network; Rooted ASUS Transformer TF101 w/ dock, Android 5.1 KatKiss; Laptop: ASUS X550C, 2.0GHzx2, 8GB, 512GB SSD, Kubuntu 15.10;
Facebook page: Skeleville Technology Solutions
well to use fgets i'd have to change most of my code.. I found a way though
scanf("%[^\ns", <variable>); Works perfectly just incase there's anyone else with such a problem
What i need now is help with checking if a interger is a char
Project > http://naturaldisastertips.com
You mean a letter right? Just check if it's between the ASCII values. 64 - 126 I think; don't quite remember exactly...
Rooted OnePlus 2 64GB Ed, Android 5.1.1 OxygenOS ; on teifin' AT&T's network; Rooted ASUS Transformer TF101 w/ dock, Android 5.1 KatKiss; Laptop: ASUS X550C, 2.0GHzx2, 8GB, 512GB SSD, Kubuntu 15.10;
Facebook page: Skeleville Technology Solutions