Shoutbox

C help! Please - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: C help! Please (/showthread.php?tid=65968)

C help! Please by .Roy on 09-08-2006 at 10:46 AM

#include <stdio.h>
#include <conio.h>
int main(void)
{
   
    printf("lol\n");
    delay(2000);
    printf("Why isnt this working?!");
   
}
   

whats wrong with this?

I think i missed an #include but i dont know which one :S. The delay seems to be the problem...


RE: C help! Please by Stigmata on 09-08-2006 at 11:09 AM

windows.h ?

i duno, that seems to be in every c code i see :D


RE: C help! Please by Eljay on 09-08-2006 at 11:13 AM

problem with delay being no such function exists? ^o)


RE: C help! Please by .Roy on 09-08-2006 at 11:31 AM

i remember when using turbo ++ delay did exist.


RE: C help! Please by RaceProUK on 09-08-2006 at 12:00 PM

#include <stdio.h>
#include <stdlib.h>
int main(void)
{
   
    printf("lol\n");
    sleep(2000);
    printf("Why isnt this working?!");
   
}

That is, if sleep() is in stdlib.h.


RE: C help! Please by .Roy on 09-08-2006 at 12:09 PM

#include <stdio.h>
#include <stdlib.h>
int main(void)
{
   
    printf("lol\n");
    sleep(2000);
    printf("Why isnt this working?!");
   
}
   
Still not working :/ sleep isnt correct :/

edit: im useing dev-c++

since i cant get turbo c++ to install >.>


RE: C help! Please by Plik on 09-08-2006 at 12:48 PM

google says to either try includeing windows.h or unistd.h ;)


RE: C help! Please by .Roy on 09-08-2006 at 01:01 PM

>.> im using dev-C++ maybe it doesnt work with this i dont know ...

I need to get another program the one i use at school... fuck thanks anyways guys, nothing worked.


RE: C help! Please by Adeptus on 09-08-2006 at 01:20 PM

I think the function you are looking for is named Sleep() with a capital S in MinGW library, and declared in windows.h -- try this:

#include <stdio.h>
#include <windows.h>
int main(void)
{
   
    printf("lol\n");
    Sleep(2000);
    printf("Why isnt this working?!");
   
}

I don't see anything here that would require inclusion of conio.h, as you seem to like to do.


RE: C help! Please by .Roy on 09-08-2006 at 01:55 PM

quote:
Originally posted by Adeptus
#include <stdio.h>
#include <windows.h>
int main(void)
{
 
    printf("lol\n");
    Sleep(2000);
    printf("Why isnt this working?!");
   
}
Thanks LOADS! :)!

Edit: And when i used turbo c ++ there was a command called gotoxy() where moves your pointer to the following coordinates, like gotoxy(5,30).

and its not working, maybe i should just use turbo c
RE: C help! Please by absorbation on 09-08-2006 at 02:54 PM

The problem is some compilers are different. At the end on the main function try adding this. For me the window opens and closes, so I think the basic solution would be adding this:

cin.get();

Edit: Using <windows> would be useless and just add to the filesize as the program is using nothing from the Windows API :P


RE: C help! Please by Adeptus on 09-08-2006 at 03:17 PM

quote:
Originally posted by .Roy
And when i used turbo c ++ there was a command called gotoxy() where moves your pointer to the following coordinates, like gotoxy(5,30). and its not working, maybe i should just use turbo c
If you are going to want to do things like that (which may not seem much, but believe it or not, are not part of the "standard" library you can always count on), then it may be best to settle on one compiler.

There are three parts to what you are learning: the C language syntax; the standard library, which is very minimal; interacting with the OS and hardware.   The language and the standard library will be the same across different compilers.  Support for interacting with the system beyond what is provided by the standard library will vary -- not just between operating systems, but even between different compilers.  This is what you have been encountering.

You may find this tutorial useful for your cursor positioning needs.

If you need to :google: anything relevant to Dev-C++, include the keyword "MinGW" in your query, as that is the name of the compiler and libraries behind Dev-C++.
RE: C help! Please by RaceProUK on 09-08-2006 at 03:41 PM

quote:
Originally posted by absorbation
Using <windows> would be useless and just add to the filesize as the program is using nothing from the Windows API
No it wouldn't, as the linker will just chuck away anything that isn't used.
quote:
Originally posted by Adeptus
declared in windows.h
If you wish to use the Windows Sleep function, yes. However, I believe the standard C library has a sleep() too, in unistd.h (I just Googled it :P).

And, as always, remember that different compilers and systems have different libraries.
RE: C help! Please by absorbation on 09-08-2006 at 03:44 PM

quote:
Originally posted by RaceProUK
No it wouldn't, as the linker will just chuck away anything that isn't used.

Dev-C++ is having some troubles with me at the moment doing that, Visual Stuido didn't, looks like I need to check my configuration or find the cause. Thanks :)

It is pretty bad, a simple Hello World program seems to turn into 1MB in size, I need to fix it ASAP, it has only recently happened :(
RE: C help! Please by Adeptus on 09-08-2006 at 03:57 PM

quote:
Originally posted by RaceProUK
If you wish to use the Windows Sleep function, yes. However, I believe the standard C library has a sleep() too, in unistd.h.
This would be true where the full POSIX API is implemented.  MinGW libraries, however, do not have it.

I feel that was a wise decision on their part.  While it would have been very easy to #define it to Windows Sleep() call, there are expectations for POSIX sleep() in regard to signal handling, which could not be met -- in other words, it would be broken.
RE: C help! Please by .Roy on 09-08-2006 at 04:36 PM

I think im going to just use the program that our school uses.
Turbo c/c++

since then i wont have any trouble. Thanks a lot guys :)


RE: RE: C help! Please by segosa on 09-08-2006 at 08:07 PM

quote:
Originally posted by absorbation
quote:
Originally posted by RaceProUK
No it wouldn't, as the linker will just chuck away anything that isn't used.


It is pretty bad, a simple Hello World program seems to turn into 1MB in size, I need to fix it ASAP, it has only recently happened :(


Try compiling it in release mode, not debug.
RE: RE: C help! Please by andrewdodd13 on 09-08-2006 at 08:16 PM

quote:
Originally posted by .Roy
quote:
Originally posted by Adeptus
#include <stdio.h>
#include <windows.h>
int main(void)
{
 
    printf("lol\n");
    Sleep(2000);
    printf("Why isnt this working?!");
   
}
Thanks LOADS! :)!

Edit: And when i used turbo c ++ there was a command called gotoxy() where moves your pointer to the following coordinates, like gotoxy(5,30).


I believe the command for gotoxy(x,y) using windows.h is SetCursorPosition(int left, int top). I haven't ever used Dev-C++ - my school were nice enough to give me an old copy of VS6 until .NET 2005 express came out - so this command may not work.

Just make sure you do #include <windows.h> first :)

PS. Just checked, I don't think that command works in C. Use the following:

code:
#include <conio.h>
#include <stdio.h>

int main (void)
{
gotoxy(10,10);
printf("Starts on location 10,10.\n");

return 0;
}


RE: C help! Please by .Roy on 09-08-2006 at 09:48 PM

Gah i always thought "C" was a scripting language that is the same with every program :S wtfux...


RE: C help! Please by ShawnZ on 09-08-2006 at 10:02 PM

quote:
Originally posted by .Roy
Gah i always thought "C" was a scripting language that is the same with every program :S wtfux...

C is a specification, not a scripting language. Functions are provided by libraries that come with your compiler, which allow you to use functions provided by the operating system you're using.