reg 'system' function--- wid a simple code!

H

Harsh_forC

hello folks,

here i m inserting d very simple code tat im trying to execute..
but still gettin d same error msg,.." Not enuf memory"

#include<stdlib.h>
#include<stdio.h>

void main(void)
{
int p;

p=system("time");

if(p<0)
{
perror("Error:");
exit(1);
}
}


i also tried executing dis code in my frd's comp. whoz havin double d
memory
than im havin..
but still gettin d same msg.

wat to do?
 
R

Richard Heathfield

Harsh_forC said:
hello folks,

here i m inserting d very simple code tat im trying to execute..
but still gettin d same error msg,.." Not enuf memory"

If you are getting that error message, consider replacing your operating
system with one written by someone who knows English.
#include<stdlib.h>
#include<stdio.h>

void main(void)

Stop right there. main returns int. If you define main as having any other
return type, the C language disowns your program completely, and does not
define what will happen.
{
int p;

p=system("time");

if(p<0)

The meaning of the return value of system() is implementation-dependent.
Check your documentation.
 
A

Albert

Richard Heathfield:
There is no reason why it should. It is not a valid C program.

Here's what I say in return - I compiled it successfully and changed my
system's time and clock successfully.
 
J

Jack Klein

hello folks,

here i m inserting d very simple code tat im trying to execute..
but still gettin d same error msg,.." Not enuf memory"

You'll get better results if you don't write like an idiot.
#include<stdlib.h>
#include<stdio.h>

void main(void)

Oops, not a valid C program once you define main() with a return type
of void instead of int.
{
int p;

p=system("time");

if(p<0)
{
perror("Error:");
exit(1);
}
}


i also tried executing dis code in my frd's comp. whoz havin double d
memory
than im havin..
but still gettin d same msg.

wat to do?

Make an effort to use proper spelling and grammar, and get rid of the
stupid abbreviations and SMS chat usage.

Then go back and read the answers you got when you posted the same
question yesterday. Especially the one by Madhav.
 
R

Richard Heathfield

Albert said:
Richard Heathfield:


Here's what I say in return - I compiled it successfully and changed my
system's time and clock successfully.

That's as may be, but it is still not a valid C program.
 
K

Kenny McCormack

Harsh_forC said:
i also tried executing dis code in my frd's comp. whoz havin double d
memory
than im havin..
but still gettin d same msg.

wat to do?

Speak English maybe?
 
M

Mark McIntyre

hello folks,

here i m inserting d very simple code tat im trying to execute..
but still gettin d same error msg,.." Not enuf memory"

I very much doubt your computer printed that message.

(top tip: in CLC do not use abbreviations of words, this is not a
mobile phone / IM).

As for your code:
a) main returns an int, not void. Returning anything other than an int
is not well defined and may not work.

b) the return value of system is implementation defined, you can't
check it like that.

c) you may not be able to execute 'time' like that - eg on MSDOS &
Windows its a builtin shell command so you may need to invoke the
shell first. For more info, ask in a Windows programming group as the
precise details of that are offtopic here.
Mark McIntyre
 
J

Joe Wright

Harsh_forC said:
hello folks,

here i m inserting d very simple code tat im trying to execute..
but still gettin d same error msg,.." Not enuf memory"

#include<stdlib.h>
#include<stdio.h>

void main(void)
{
int p;

p=system("time");

if(p<0)
{
perror("Error:");
exit(1);
}
}


i also tried executing dis code in my frd's comp. whoz havin double d
memory
than im havin..
but still gettin d same msg.

wat to do?

Learn to write English. Pay more attention writing C code. The following
works as I expect on my machine. How about yours?

#include<stdlib.h>
#include<stdio.h>

int main(void) {
int p;
p = system("time");

if (p < 0) {
perror("Error:");
exit(1);
}
return 0;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top