Computer Hope

Software => Computer programming => Topic started by: Joleen on May 13, 2004, 05:07:27 AM

Title: C programming
Post by: Joleen on May 13, 2004, 05:07:27 AM
I am re-learning C and have an issue.  Once I compile I run my app (good ol' Hello World).  The dos window opens, displays my "Hello World", then promptly shuts down again.  How can I get the window to stay open if I have more text I want to check.  Is there a way to configure the command.exe to stay open or do I need code awaiting a user response?  If I need code.. can you supply the syntax?
Title: Re: C programming
Post by: William Todd on May 14, 2004, 12:14:59 AM
I have the same problem if any can help please net me know.

Title: Re: C programming
Post by: sky on May 14, 2004, 12:20:59 PM
Hi Joleen,

I believe there's 2 solutions:

1 - open a c prompt, navigate to your folder, type your program command. At the end of program execution, u r return to c prompt n u can c your program.

2 - more professionally, code in your c program to pause/stop at the end of code. 1 way is to code the cin.get() command just b4 return 0 (or similiar commands) that REQUIRES user input to continue the program. Ths way, the program waits at the end so u have smthng like window stay open. I used Bloodshed Dev C compiler, and there's a system.pause (or similiar) command that pause the cmd window. will try to find out the exact code 4 u guys.

SKy
Title: Re: C programming
Post by: Joleen on May 14, 2004, 12:37:18 PM
I get a compile error with cin.get(); as noted in this thread..

http://www.computerhope.com/cgi-bin/yabb/YaBB.cgi?board=2;action=display;num=1084368024;start=0#6

I can use this..

scanf("%d",&response);
printf( "%s/n", response );

and it works fairly well for now.


I have been going into dos via cmd.exe and running my tests from the command line which works but I hate the extra work.  If I liked work I wouldn't be programming computers to do it for me ;)
Title: Re: C programming
Post by: Joleen on May 14, 2004, 12:47:12 PM
I have the Bloodshed C++ compiler, is it the same?  I'm using Miracle C right now but I like the Bloodshed better.  If Bloodshed C++ will work for C then I'll switch.

I took C for about a week and that was about 2.5 yrs ago.  Now my boss wants to save 500USD by having me write code that access a barcode scanner.  *code to follow*  I can do it but it will end up costing more that it'll save because of the time I have to learn and lost time from other projects. <sigh>Oh well</sigh>

Bear in mind.. I didn't write this, I just have to tweak it and install it on a handheld barcode scanner.

#include <jcntl.h>
#include <defn.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <io.h>
#include <rcd.h>
#include <lookup.h>
#include <fcntl.h>
#include <fio.h>
#include <ctype.h>

struct CtrlCenter ccnt;

/*** all data */

char _collect2[17]; // 1..15, len includes terminator \0
char _collect3[11]; // 1..10, len includes terminator \0
char _collect4[9]; // 0..8, len includes terminator \0

/*** all global programs */

#line -

/*** all expressions */

int __GetExpression(int jid)
{
     int _RESULT_ = 0;

     #line -

     return _RESULT_;
}

/*** all control data */

struct CtrlData __cdata[] = {
40003, "\x01",
40002, "\x08\x54\x72\x75\x63\x6B\x30\x30\x31\x2E\x73\x68\x70\x08\x01"
"\x09\x54\x72\x75\x63\x6B\x30\x30\x31\x2E\x73\x68\x70\x09\x01"
"\x01\x00",
40021, "\x00\x00",
40020, "\x54\x72\x75\x63\x6B\x30\x30\x31\x2E\x73\x68\x70\x00",
40019, "\x54\x72\x75\x63\x6B\x30\x30\x31\x2E\x73\x68\x70\x00",
40018, "\x63\x6F\x6C\x6C\x65\x63\x74\x33\x09\x03\x01\x63\x6F\x6C\x6C"
"\x65\x63\x74\x34\x09\x04\x01\x63\x6F\x6C\x6C\x65\x63\x74\x32"
"\x09\x02\x01\x00",
40017, "\x03\x04\x02\x00",
40014, "\x0B\x00",
40013, "\x0A\x00",
40001, "\x6D\x65\x6E\x75\x31\x09\x01\x01\x63\x6F\x6C\x6C\x65\x63\x74"
"\x32\x09\x02\x01\x63\x6F\x6C\x6C\x65\x63\x74\x33\x09\x03\x01"
"\x63\x6F\x6C\x6C\x65\x63\x74\x34\x09\x04\x01\x00",
8050, "\x05\x09\x0A\x20\x80\x02\x00\x00\x00\x00\x5F\x22\x84\x00\x00"
"\x00\x08\x29\x01\x00\x2C\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00"
"\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00",
8049, "\x00",
8051, (char*)&_collect4,
8038, "\x05\x0B\x0A\x20\x80\x02\x00\x00\x00\x00\x2E\x13\x80\x00\x00"
"\x01\x0A\x29\x01\x00\x2C\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00"
"\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00",
8037, "\x00",
8039, (char*)&_collect3,
8026, "\x04\x11\x0A\x03\x80\x02\x00\x00\x00\x00\x2E\x03\x80\x00\x00"
"\x01\x0F\x29\x01\x00\x2C\xFF\xFF\xFF\xFF\x00\x00\x00\x00\x00"
"\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00",
8033, "\x03\x09\x05\x01\x01\x15\x06\x01\x14\x05\x13\x0D\x11\x0D\x12\x0D\x02\x01\x00",
8025, "\x00",
8027, (char*)&_collect2,
4014, "\x00\x00\x02\x00",
4013, "\x52\x65\x61\x64\x79\x20\x74\x6F\x20\x73\x63\x61\x6E\x00",
44002, "\x00",
44001, "\x37\x34\x31\x08\x00\x86\x0D\x00\x38\x35\x32\x30\x11\x13\x87"
"\x00\x39\x36\x33\x2E\x10\x12\x88\x00\x00\x00\x00\x00\x20\x80"
"\x89\x00\x41\x4A\x53\x08\x00\x86\x0D\x00\x44\x4D\x56\x40\x11"
"\x13\x87\x00\x47\x50\x59\x3B\x10\x12\x88\x00\x00\x00\x00\x00"
"\x20\x80\x89\x00\x42\x4B\x54\x08\x00\x86\x0D\x00\x45\x4E\x57"
"\x3F\x11\x13\x87\x00\x48\x51\x5A\x2E\x10\x12\x88\x00\x00\x00"
"\x00\x00\x20\x80\x89\x00\x43\x4C\x55\x08\x00\x86\x0D\x00\x46"
"\x4F\x58\x26\x11\x13\x87\x00\x49\x52\x5F\x2C\x10\x12\x88\x00"
"\x00\x00\x00\x00\x20\x80\x89\x00\x23\x3A\x2D\x5C\x84\x8A\x0D"
"\x00\x24\x3D\x2B\x27\x11\x93\x8B\x00\x25\x2F\x2A\x21\x10\x92"
"\x8C\x00\x00\x00\x00\x00\x20\x80\x8D\x00",
44003, "\x00",
0,0
};

struct CtrlCenter ccnt =
{
"PT-600",
"C:\JGLITE\Truck001.JGP",
"",
1,
0,
5,
4,
"\x01\x01\x02\x02\x03\x02\x04\x02\x00",
"\x00",
"\x01\x01\x02\x00\x41\x00\x02\x02\x03\x00\x21\x00\x03\x03\x04"
"\x00\x02\x00\x04\x04\x02\x01\x82\x00\x00",
1,
1,
1,
2,
16,
8,
16,
8,
12,
4,
1,
2,
0,
"\x45\x78\x69\x74\x20\x28\x31\x2D\x59\x2F\x30\x2D\x4E\x29\x3F"
"\x00",
"\x44\x6F\x6E\x65\x00",
"\x41\x62\x6F\x72\x74\x00",
"\x42\x72\x6F\x77\x73\x65\x00",
"\x44\x61\x74\x61\x00",
"\x45\x64\x69\x74\x00",
"\x46\x6F\x75\x6E\x64\x00",
"\x4D\x6F\x64\x69\x66\x79\x20\x66\x69\x65\x6C\x64\x3F\x00",
"\x4E\x6F\x20\x64\x61\x74\x61\x00",
"\x4E\x6F\x74\x20\x66\x6F\x75\x6E\x64\x00",
"\x53\x65\x61\x72\x63\x68\x00",
"\x53\x65\x61\x72\x63\x68\x20\x6E\x65\x78\x74\x00",
"\x57\x61\x69\x74\x2E\x2E\x2E\x00",
"\x45\x72\x61\x73\x65\x20\x61\x6C\x6C\x3F\x00",
"\x45\x72\x61\x73\x65\x20\x6C\x61\x73\x74\x3F\x00",
"\x53\x65\x6E\x64\x20\x64\x61\x74\x61\x00",
"\x4E\x6F\x20\x72\x65\x63\x6F\x72\x64\x00",
"\x54\x6F\x74\x61\x6C\x00",
"\x46\x69\x6C\x65\x20\x6E\x6F\x74\x20\x66\x6F\x75\x6E\x64\x21"
"\x00",
"\x4F\x70\x65\x6E\x20\x66\x69\x6C\x65\x20\x65\x72\x72\x6F\x72"
"\x21\x00",
"\x52\x65\x61\x64\x20\x66\x69\x6C\x65\x20\x65\x72\x72\x6F\x72"
"\x21\x00",
"\x57\x72\x69\x74\x65\x20\x66\x69\x6C\x65\x20\x65\x72\x72\x6F"
"\x72\x21\x00",
"\x57\x72\x69\x74\x65\x20\x72\x65\x63\x6F\x72\x64\x20\x65\x72"
"\x72\x6F\x72\x21\x00",

(void*)__cdata,
(void*)__GetExpression,

15036
};

int _jobinit() {return (int)&ccnt;}


Title: Re: C programming
Post by: SKy on May 17, 2004, 07:49:25 PM
Hi Joleen,

- (works in most compilier) to use a cin command:

 int main(){
............
.............;

int x;
std::cin>>x;
return 0;}

- For Bloodshed C++, you can type

#include<stdlib.h>

int main(){
...............
...............;

system("pause");
return 0;}
Title: Re: C programming
Post by: Joleen on May 18, 2004, 05:29:43 AM
I've just about given up on the cin.

The code..

#include <stdio.h>
char      *format = "%s",
     *hello = "Hello World...\n";
int x;

main()
{
     std::cin>>x;
     return 0;
}

The Error..

Miracle C Compiler (r3.2), written by bts.
Compiling c:\temp\c code\hello.c
main

c:\temp\c code\hello.c: line 10: Parse Error, expecting `'}''
':cin>>x'
aborting compile
Title: Re: C programming
Post by: Joleen on May 18, 2004, 08:46:06 AM
**Update**

I've found a compiler called Pelles C for Windows and it works much better than Miracle C.  Heck, it even keeps the dos window open for me.. what a gentleman.
Title: Re: C programming
Post by: sky on May 18, 2004, 10:59:42 PM
: ) dat's nice to heard.

anyway the full src code for hello world shd b smthng like:

#include<iostream.h>

int main{

cout<<"Hello World...\n";

int x;  
std::cin>>x;
return 0;}
Title: java programming
Post by: john20004 on June 14, 2004, 02:47:14 AM
every time i want to compile ,
for example :
javac HelloWorld.java
i read
Error canīt read , 1 erorr

Title: Re: C programming
Post by: Addy on August 04, 2004, 11:16:52 AM
Although you seem to have found a solution, this might help:
Open the Windows Explorer and locate your executable. Right-click on it and select "Properties" (should be on the bottom of the menu). Find the option which keeps the window open after the program terminates (I can't tell you more details as I abandoned Windows a while ago).
Now you do not need to start your program from the compiler.
Title: Re: C programming
Post by: Nosophorus on September 02, 2004, 04:23:22 AM
Simple.

First, add the #include<stdlib.h>, after do that write system("PAUSE") at the final of your C code inside the main function.
Title: Re: C programming
Post by: Joleen on September 02, 2004, 05:46:07 AM
Thanks for the reply but where were you 6 months ago when I posted the question?

It turns out the project was outsourced so I was let off the hook for making it work.