Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming

Reply
 
LinkBack Thread Tools
Old 3 Weeks Ago   #1 (permalink)
WaterCooler
 
mtbhrd's Avatar
 
intel ati

Join Date: Aug 2008
Posts: 405

Rep: 28 mtbhrd is acknowledged by some
Unique Rep: 27
Trader Rating: 1
Default MS: Running test file for C program

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!
__________________

System: Lemurs, man. Lemurs.
CPU
E8500 C0 @ 4.28 GHz
Motherboard
Asus Rampage Formula (x48)
Memory
2x 2gb, DDR2 1066, G.Skill
Graphics Card
VisionTek 4870
Hard Drive
1Tb Black | 1Tb F1 | 500gb ST
Sound Card
Supreme FX II
Power Supply
Antec Truepower 850w
Case
NZXT Tempest
CPU cooling
ApogeeGTZ, GTX360, MCP655
GPU cooling
DD Block
OS
Vista Ult. x64
Monitor
Asus 24" MK241H
mtbhrd is offline   Reply With Quote
Old 3 Weeks Ago   #2 (permalink)
Programmer
 
newbie1911's Avatar
 
Join Date: Jul 2008
Posts: 319

Rep: 19 newbie1911 Unknown
Unique Rep: 17
Trader Rating: 0
Default

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.
newbie1911 is offline   Reply With Quote
Old 3 Weeks Ago   #3 (permalink)
4.0 GHz
 
dharmaBum's Avatar
 
intel nvidia

Join Date: Apr 2007
Location: Raleigh, NC
Posts: 747

Rep: 121 dharmaBum is acknowledged by manydharmaBum is acknowledged by many
Unique Rep: 89
Trader Rating: 0
Default

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:
There are only two industries that refer to their customers as ‘users’.

System: Europa
CPU
E8500 4.36ghz @ 1.36v
Motherboard
EVGA 780i SLi P05 Bios
Memory
G.SKILL 4GB(2x2GB) @ 924MHz (5-4-4-12-2T)
Graphics Card
2xEVGA 8800GTS (G92) 512MB @800/2000/2110
Hard Drive
Seagate 500gbx2, (fake-)RAID0
Sound Card
Sound Blaster X-Fi XtremeGamer
Power Supply
CORSAIR 1000HX 1000W
Case
Gigabyte GZ-FA2CA-AJB Black Aluminum
CPU cooling
TDX 775 Block, 360 BlackIce rad
GPU cooling
MAZE5x2, TT copper HS
OS
Fedora10-86_64/Vista64
Monitor
22" Samsung SyncMaster 2232BW

Last edited by dharmaBum : 3 Weeks Ago at 06:08 PM
dharmaBum is online now   Reply With Quote
Old 3 Weeks Ago   #4 (permalink)
WaterCooler
 
mtbhrd's Avatar
 
intel ati

Join Date: Aug 2008
Posts: 405

Rep: 28 mtbhrd is acknowledged by some
Unique Rep: 27
Trader Rating: 1
Default

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)
__________________

System: Lemurs, man. Lemurs.
CPU
E8500 C0 @ 4.28 GHz
Motherboard
Asus Rampage Formula (x48)
Memory
2x 2gb, DDR2 1066, G.Skill
Graphics Card
VisionTek 4870
Hard Drive
1Tb Black | 1Tb F1 | 500gb ST
Sound Card
Supreme FX II
Power Supply
Antec Truepower 850w
Case
NZXT Tempest
CPU cooling
ApogeeGTZ, GTX360, MCP655
GPU cooling
DD Block
OS
Vista Ult. x64
Monitor
Asus 24" MK241H

Last edited by mtbhrd : 3 Weeks Ago at 08:55 PM
mtbhrd is offline   Reply With Quote
Old 3 Weeks Ago   #5 (permalink)
4.0 GHz
 
dharmaBum's Avatar
 
intel nvidia

Join Date: Apr 2007
Location: Raleigh, NC
Posts: 747

Rep: 121 dharmaBum is acknowledged by manydharmaBum is acknowledged by many
Unique Rep: 89
Trader Rating: 0
Default

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);
...
}
This way, when you run the code (from any shell) you simple supply the name of a text file. (You need to compile the program and produce a binary/executable). Linux example:

Code:
 user@localhost> myapp myfile.txt
and would be run the same way with Windows prompt.

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:
There are only two industries that refer to their customers as ‘users’.

System: Europa
CPU
E8500 4.36ghz @ 1.36v
Motherboard
EVGA 780i SLi P05 Bios
Memory
G.SKILL 4GB(2x2GB) @ 924MHz (5-4-4-12-2T)
Graphics Card
2xEVGA 8800GTS (G92) 512MB @800/2000/2110
Hard Drive
Seagate 500gbx2, (fake-)RAID0
Sound Card
Sound Blaster X-Fi XtremeGamer
Power Supply
CORSAIR 1000HX 1000W
Case
Gigabyte GZ-FA2CA-AJB Black Aluminum
CPU cooling
TDX 775 Block, 360 BlackIce rad
GPU cooling
MAZE5x2, TT copper HS
OS
Fedora10-86_64/Vista64
Monitor
22" Samsung SyncMaster 2232BW
dharmaBum is online now   Reply With Quote
Old 3 Weeks Ago   #6 (permalink)
WaterCooler
 
mtbhrd's Avatar
 
intel ati

Join Date: Aug 2008
Posts: 405

Rep: 28 mtbhrd is acknowledged by some
Unique Rep: 27
Trader Rating: 1
Default

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.
__________________

System: Lemurs, man. Lemurs.
CPU
E8500 C0 @ 4.28 GHz
Motherboard
Asus Rampage Formula (x48)
Memory
2x 2gb, DDR2 1066, G.Skill
Graphics Card
VisionTek 4870
Hard Drive
1Tb Black | 1Tb F1 | 500gb ST
Sound Card
Supreme FX II
Power Supply
Antec Truepower 850w
Case
NZXT Tempest
CPU cooling
ApogeeGTZ, GTX360, MCP655
GPU cooling
DD Block
OS
Vista Ult. x64
Monitor
Asus 24" MK241H
mtbhrd is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -5. The time now is 11:19 PM.


Overclock.net is a Carbon Neutral Site Creative Commons License

Terms of Service / Forum Rules | Privacy Policy | DMCA Info | Advertising | Become an Official Vendor
Copyright © 2009 Shogun Interactive Development. Most rights reserved.
Page generated in 0.11927 seconds with 8 queries