|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming | |
MS: Running test file for C program
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) | |||||||||||||
|
WaterCooler
![]() |
Hey, so I need to run a test file, say in1.txt that contains input for a C program. I know how do this on the linux machines we are using just from the terminal-
But when I'm back on my MS rig, I'm not sure how to include the test file when running my program. Usually just run my program off code::blocks. It has a 'set program arguments' option, but it never seems to work. So I'd like to find out how to either use code::blocks or cmd prompt to run a test file in windows. Thanks!
__________________
|
|||||||||||||
|
|
|
|
|
#2 (permalink) |
|
Programmer
|
do you want to read it or run it?
http://www.phanderson.com/files/file_read.html to read it. cant really find anything about executing a program in c unless its the same as this c++ example http://www.cplusplus.com/forum/beginner/868/
__________________
90% of statistics are made up on the spot. including this one.
|
|
|
|
|
|
#3 (permalink) | ||||||||||||||
|
4.0 GHz
![]() |
If I understand the problem correctly (which I might not)...
You have two options. If you simply want to run the program, then: Edit: There's a way to do this without a prompt; if you right-click the executable and select properties you might be able to add program options, but I can't remember the specifics of this method. i.) use Start->Run and type "cmd" to get a prompt. ii.) navigate to where your built program is and simply execute it by typing the name and the inputfile (ex: ">myapp myinput.text"), as you would in a linux shell. *Note: If you haven't already you may want to install Windows PowerShell and use this instead of the standard command prompt.* OR, if you just need to run it to test it (rather than run it on any particular machine), and assuming the code is stored on computer running an SSH server (and is on) i.) Download putty ii.) SSH (login) to whatever computer has the code iii.) Business as usual. *Note: this method simply runs the code on the remote machine as if you were sitting in front of it, so again if this is something you need to be portable then this is pretty useless.
__________________
3DMark06: 19091 - 3DMark Vantage: P15264 - SuperPi: 10.968s Programming Quote of the Day: Bjarne Stroustrup: Quote:
Last edited by dharmaBum : 3 Weeks Ago at 06:08 PM |
||||||||||||||
|
|
|
|
|
#4 (permalink) | |||||||||||||
|
WaterCooler
![]() |
dharma, you got it for the most part: The second method is almost exactly what I've been doing.
I edit and compile my program in code::blocks, then use ssh to transfer my blah.c file over, and use the terminal to test my program with test inout files located on the server. This is a bit tedious when you do it a hundred times during debugging. Code::Blocks runs the program from a command prompt when you click build and run. I don't want to manual type in 100 numbers though. Is there a way to configure it to use a .txt file from my hard drive? Maybe something to do with using a project? I know when I use the debugger and breakpoints, my c file has to be in a project. (I use ' scanf() ' to read in data)
__________________
Last edited by mtbhrd : 3 Weeks Ago at 08:55 PM |
|||||||||||||
|
|
|
|
|
#5 (permalink) | ||||||||||||||
|
4.0 GHz
![]() |
Okay, so you want to pass a text file (or, more specifically, the name of a text file) to a program you are running. (correct me again if I'm wrong, I can be dense.)
generally the setup would be this: Code:
...
int main(int argc,char *argv[]) {
...
/*argc holds the number of arguments passed to the program*/
/*argv[0] holds the program name*/
/*argv[1] thorugh argv[argc] is the sequencial list of arguments*/
/*passed to the program*/
char filename[] = argv[1];
/*arbitrary open file function*/
openfile(filename);
...
}
Code:
user@localhost> myapp myfile.txt If you use Linux or Windows, you need to compile it for whichever you're working in. This method is most general, and as far as it I know doesn't matter what you compile with.
__________________
3DMark06: 19091 - 3DMark Vantage: P15264 - SuperPi: 10.968s Programming Quote of the Day: Bjarne Stroustrup: Quote:
|
||||||||||||||
|
|
|
|
|
#6 (permalink) | |||||||||||||
|
WaterCooler
![]() |
No, what I'm talking about is simpler than that. In my C code, I have scanf functions that read input.
On a linux machine, I simply run the command in terminal ' a.out < .......\in1.txt ' where the ... is an address on the school server that I'm connected to. I'm running my editor and compiler off that server. I want to be able to do this on a windows machine. I appreciate the help so far .. but the suggestions are not what I'm looking for.
__________________
|
|||||||||||||
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|