![]() |
|
#1
|
|||
|
|||
NOT sure what is wrong with script fscanfHi there,
I have been working on this script to learn C and I am hung up on some minor problem. The script is suppose to read imput.txt from my c drive then check to see if the numbers in imput.txt are Prime or not as well as perfect or not. I compiled my program and got 0 errors but when I get to the black popup box a windows pop up comes up stating these issues "Found the comment. When I execute the script it gives me no errors until it brings up the black box and then another window pops up and says Windows debug failed. Line 54 fscanf.c Then says that Expression: Stream != NULL" Here is my script!!! ANT CLUES? I think I have been staring at it too much. I am new to C. CPP / C++ / C Code:
Last edited by LuciWiz : 29-Oct-2004 at 04:52.
Reason: Please insert your c code between [c] & [/c] code
|
|
#2
|
||||
|
||||
|
Hello jenmaz. Welcome to GIDForums™.
Without going over the entire code, I can see several things that jump out at me immediately. First fopen should always be checked for errors. It will return null upon error. I suspect that your program is not opening the file properly and then choking when it is trying to use the FILE* CPP / C++ / C Code:
Also, you may want to call out your text file in an absolute manner. CPP / C++ / C Code:
CPP / C++ / C Code:
Hope this helps. Good luck! __________________
The best damn Sports Blog period. |
|
#3
|
|||
|
|||
Still cannot figure out why my input file won't openHi there,checked for errors and even moved my file to the D drive and it is still not being recognized. I still cannot figure out how to read from an input file. Should I try openning another file?
Here is what I have now. CPP / C++ / C Code:
Quote:
Last edited by dsmith : 29-Oct-2004 at 09:05.
Reason: Please use [c] & [/c] for syntax highlighting
|
|
#4
|
|||
|
|||
|
Quote:
Try this to see where it is looking for the file. (Change inname to whatever you think it should be.) The program will look for the file name that you give it in all of the directories in the path. CPP / C++ / C Code:
If you want to give it a directory name, then use something like CPP / C++ / C Code:
or CPP / C++ / C Code:
This should show you what's in the directory that you are using. Regards, Dave |
|
#5
|
|||
|
|||
Thanks it work but have another question with scriptOK I have figured that out. The file was named input.txt.txt and I could not see that. Now I am trying to activat my functions so that when the data is read from the file it gets executed by both Prime and perfect functions to determine and print on screen if the number is prime, not prime and/or perfect, not perfect. When looking at my code do you see something on when I try to call the functions? I have 10 errors and not sure how to resolve it.
Here is the Code. CPP / C++ / C Code:
Last edited by JdS : 07-Nov-2004 at 06:01.
Reason: Please insert your example C/C++ codes between [c] and [/c] tags
|
|
#6
|
|||
|
|||
|
I would also like to write a function that allows the user to close or quit out of the program by typing in y for yes or n for no. The function would return a character indicating the user response for the question “Do you want to try another file?”
Any ideas. I am just now learning functions and if I see it I can understand it. Thanks in advance, Jennifer |
|
#7
|
|||
|
|||
|
Quote:
Before trying to enhance the program, I respectfully suggest that you get it working first. You really should try to use consistent indenting to see where your control structures are. Here is a slightly modified listing of your code. NOte that an extra "}" near the end of Perfect() completely screwed up everything afterwards. CPP / C++ / C Code:
Note that after removing this bracket there are still some errors. I'll help with a couple; you should try to see what the others are: when calling a function, just put in the argument, not the type. That is, change this CPP / C++ / C Code:
to this CPP / C++ / C Code:
Regards, Dave |
|
#8
|
|||
|
|||
Thanks it is running but now I just need...Everything is running and the script checks the data and I get output from the data. Unfortunately the Prime scripts and Perfect formulas are not correct. Since I am not good in math do you know where I could find these functions?
Jennifer PS Thanks... I found a lot of the issues once you pointed out some |
|
#9
|
|||
|
|||
|
Quote:
I perceive that you have the right idea for an implementation of Prime(). That is, you simply see if anything greater than 1 and less than n is an exact divisor of n Look at your function: CPP / C++ / C Code:
Now, as you have written it, n is the number that you passed to the function to test to see if it is prime. Now, you can't declare a local variable with the same name as the argument that you used. so there are some obvious errors here. I would like to see your code, but to save time, I will make a slight modification: CPP / C++ / C Code:
Where I have deleted superfluous variables not used in this function. Now, what's wrong? A typographical error: what's i in the expression CPP / C++ / C Code:
Well, there is no i anywhere, so you must have meant n. So now we have CPP / C++ / C Code:
What's the loop doing? If it ever finds a divisor, then it knows the number is not a prime, so it sets the variable IsPrim to 0. I would make the printout a little more informative: CPP / C++ / C Code:
With this to get you started, you should be able to get a little farther. You can clean up the output to your taste. If you have any more questions, show us what you did, what you got, what you expected, and what you don't understand. Regards, Dave |
|
#10
|
|||
|
|||
getting what the issue is but having trouble resolving itHi there,
I fixed the i variable it was suppose to be n (to my knowledge). I just forgot to change it. I am still weak at looking over these minor mistakes. I then placed your code if ( num % n == 0) { IsPrim=0; printf("%d is a divisor of %d\n", n, num); In the script so that we could see the output. So when I ran the program and it read these numbers from my input.txt file 6 7 28 18 496 31 24 17 36 3 19 -999 It gave me this out put which shows me that the script is reading the numbers (12 all together and stopping at -999) however it is not out puting properly because n is now = 2 not = to the input number. Then it displays n = 2 and its division and it is the same output for each 12 data imput from the text file. Here is the output 2 is a divisor of -858993460 -858993460 is a divisor of 2 2 is a divisor of -858993460 -858993460 is a divisor of 2 2 is a divisor of -858993460 -858993460 is a divisor of 2 2 is a divisor of -858993460 -858993460 is a divisor of 2 2 is a divisor of -858993460 -858993460 is a divisor of 2 2 is a divisor of -858993460 -858993460 is a divisor of 2 2 is a divisor of -858993460 -858993460 is a divisor of 2 2 is a divisor of -858993460 -858993460 is a divisor of 2 2 is a divisor of -858993460 -858993460 is a divisor of 2 2 is a divisor of -858993460 -858993460 is a divisor of 2 2 is a divisor of -858993460 -858993460 is a divisor of 2 2 is a divisor of -858993460 -858993460 is a divisor of 2 Press any key to continue I understand now what is going wrong but not sure how to fix it. Thanks in advance. jen |
Recent GIDBlog
Observations of Iraq by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Two virtual hosts, cgi script behaves differently on each | blimbo | Apache Web Server Forum | 0 | 04-Aug-2004 09:35 |
| Where can I find web statistics script / software? | rhino1616 | Web Design Forum | 2 | 02-Jan-2004 20:31 |
| Redirect multiple URLs to one script, masking true URL | Maccaday | Apache Web Server Forum | 1 | 10-Dec-2003 08:34 |
| JavaScript Tutorial Part 1 | pcxgamer | Web Design Forum | 2 | 01-Dec-2003 09:16 |
| VALIDATING file types on an PHP upload script? | JdS | MySQL / PHP Forum | 0 | 02-Jan-2003 07:58 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The