Hmm,first sorry for some grammar mistakes...
I have a big problem with graphics in C... For 2 days i'm looking on internet and nothing...I saw some theards and posts but none of the lib didn't work...(It was forums on my language )
I'm working in VS 6.0 I saw here that lib "graphics.h" is old as a Rome,and i lost my time on it for 2 days,because i didn't figure why program wont work.
Can anybody tell me how can i do graphics in C...I find some function for windows but always get 1 warning,for conversion...
Or suggest some book or tut for it...
I look at one theard,where someone posted one link with lib "graphics2" but that didn't work too..
P.S I'm newcomer in programming
Tnx...
John A 1,896 Vampirical Lurker Team Colleague
It's kind of hard to read your post, but I don't blame you... graphics.h
is a header file that is only for Turbo C, so don't bother trying to use it. ;)
Are you trying to write console or Windows graphics? For console graphics, you can't use libraries such as DirectX or OpenGL. Usually the easiest method to use on Windows is to use the Win API to do your console graphics. I suggest you start here:
http://www.daniweb.com/code/snippet173.html
For going further, use Google; there's tons of information out there.
If you're trying to do Windows graphics, I recommend not using the Windows HDI and instead use an external library such as SDL, OpenGL, DirectX, etc. Also, I suggest you check out this thread on game development:
http://www.daniweb.com/techtalkforums/thread63827.html
Hope this helps
dukiduki 0 Newbie Poster
I'm very sorry :( I didn't have many chance to have chat on English...
My knowlege is enough for undrestanding it and read it.
I was on google ofcourse and i didn't find anything what will work (i was looking for one-two days,maybe i should more)
I work in console application...
I find one book on google but there i saw "graphics.h" and i lost one hour writing code which won't work...
Tnx ...I will look that link u posted...
See,I live in Serbia i supose u heard on the news, something is true most is not,but that is not important. Because of that problems IT here is still in process...I go to private univeristy,we have software (OS is for free(ofcourse not in companys),well most of software we get here for free)that is good thing...
BUT,we don't have good books...Our translations are sad,and it is not rare that code is wrong in books.So we have only internet but most of the good books are not for free. So image how much would cost me to order something from USA etc? I'm sorry for this i wrote,but i don't want anybody think that i'm molly girl who is lazy...And want someone else solve my probs...I realy need help because i'm really short with everything.
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
Hmm,first sorry for some grammar mistakes...
We can help you out with that a little. To make your posts more understandable, English uses spaces after commas (,) and periods (.). For example, note the space after that comma. And also note the space after that period. This will help. The rest we can figure out.
As for graphics, as Joe said you have to find a graphics package that you can add to your compiler. This and this Google search may give you something to work with.
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
>>Our translations are sad,and it is not rare that code is wrong in books.
It is not your translator -- our books have those mistakes too.
>>most of the good books are not for free
One reason people write books is to make money, and they can not do that if they give their work away for free.
>>My knowlege is enough for undrestanding it and read it.
you do that very well, better than many native english-speaking people.
dukiduki 0 Newbie Poster
Are you trying to write console or Windows graphics? For console graphics, you can't use libraries such as DirectX or OpenGL. Usually the easiest method to use on Windows is to use the Win API to do your console graphics. I suggest you start here:
http://www.daniweb.com/code/snippet173.html
I copy that code in VS and it wont work, is that code C++? I didn't start learn C++ yet
I look on google ofcourse, but it takes very much time when u are newcomer and not really sure what am i looking for:confused:
I had exame in C today and i wanted to astonish my profesor with some colors on console.
We can help you out with that a little. To make your posts more understandable, English uses spaces after commas (,) and periods (.). For example, note the space after that comma. And also note the space after that period. This will help. The rest we can figure out.
Tnx very much:)
It is not your translator -- our books have those mistakes too.
One reason people write books is to make money, and they can not do that if they give their work away for free.
Ofcourse. Knowledge is expensive. It was just a comment. But see, here we give money only for hardware, we get used to have very good software for free. That is bad and it will change in a few years, but here majority have very small pays and nobody can have good things legal. When i saw how much windows cost i get shocked, appreciate that if i buy few programs it will cost like my computer.
And books...well i can say that some books in which i'm interested in have price like pay of my dad, so i can forget about buying it. I can only dig some knowledge on harder way.:eek:
To get back on subject. I see that i should look for programing tuts with win environment. I saw so much promiscuous codes and get really confused.
For graphics, well i have one book about game programming by Michael Morrison, but it is on C++, so i must wait for month or two because i didn't start learn C++. He sead (i will have trouble translate that) about DirectX that he wont use it for programing because it is compound tehnology. So i see that i should learn something about DirectX if i want use it...
Tnx u all for help very much;) :)
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
Hello there my friend. I really respect your enthusiasm but you must go a bit slow. Talking about DirectX, graphics and all that when you are just learning C / C++ is too much.
Please learn to crawl before you start running. Get your concepts about the things which are not directly related to a particular language (eg. data structures, algorithms ) a bit cleared up.
As far as books are concerned, I know they are expensive. But if you really have in your heart then nothing can stop you.
For C related free stuff you can see here.
For a really good C++ ebook you can see here and also a good site for C++ tutorials.
Hope it helped, bye.
John A 1,896 Vampirical Lurker Team Colleague
I had exame in C today and i wanted to astonish my profesor with some colors on console.
Printing text in color on the console is relatively easy, although there's no standard way to do it. On Windows, you can use the Win API to do the trick; this code snippet describes how:
http://www.google.ca/url?sa=t&ct=res&cd=2&url=http%3A%2F%2Fwww.daniweb.com%2Fcode%2Fsnippet83.html&ei=kxeoReC4JaWYgQPq7vXXAQ&usg=__at1iPZ8xdLieLzIyd8q0fq8H9wU=&sig2=52aGboJHQWjHNiaUX8suUw
And yeah, follow ~s.o.s~'s advice; he knows what he's talking about.
SID_HAN 0 Newbie Poster
Hmm,first sorry for some grammar mistakes...
I have a big problem with graphics in C... For 2 days i'm looking on internet and nothing...I saw some theards and posts but none of the lib didn't work...(It was forums on my language )
I'm working in VS 6.0 I saw here that lib "graphics.h" is old as a Rome,and i lost my time on it for 2 days,because i didn't figure why program wont work.
Can anybody tell me how can i do graphics in C...I find some function for windows but always get 1 warning,for conversion...
Or suggest some book or tut for it...
I look at one theard,where someone posted one link with lib "graphics2" but that didn't work too..
P.S I'm newcomer in programming
Tnx...
U CAN TRY AT
WWW.flazx.com
I THICK THIS WILL HELP U
John A 1,896 Vampirical Lurker Team Colleague
U CAN TRY AT
WWW.flazx.com
I THICK THIS WILL HELP U
Oh wow, that just blew me away... especially the fact that there's not a single bit of useful information there that you don't have to pay for. You might have just as well given as a link to Amazon. Or Google.
dukiduki 0 Newbie Poster
Printing text in color on the console is relatively easy, although there's no standard way to do it. On Windows, you can use the Win API to do the trick; this code snippet describes how:
http://www.google.ca/url?sa=t&ct=res&cd=2&url=http%3A%2F%2Fwww.daniweb.com%2Fcode%2Fsnippet83.html&ei=kxeoReC4JaWYgQPq7vXXAQ&usg=__at1iPZ8xdLieLzIyd8q0fq8H9wU=&sig2=52aGboJHQWjHNiaUX8suUwAnd yeah, follow ~s.o.s~'s advice; he knows what he's talking about.
It seem to be a C++ code :(
VS reports me an error :fatal error C1189: #error : "eh.h is only for C++!"
John A 1,896 Vampirical Lurker Team Colleague
Sure it's C++ code, but you could still use printf() for console output, as long as you don't mix the C and C++ I/O functions.
Just out of interest, does this code compile for you?
// color your text in Windows console mode
// colors are 0=black 1=blue 2=green and so on to 15=white
// colorattribute = foreground + background * 16
// to get red text on yellow use 4 + 14*16 = 228
// light red on yellow would be 12 + 14*16 = 236
// a Dev-C++ tested console application by vegaseat 07nov2004
#include <iostream>
#include <windows.h> // WinApi header
using namespace std; // std::cout, std::cin
int main()
{
HANDLE hConsole;
int k;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
// you can loop k higher to see more color choices
for(k = 1; k < 255; k++)
{
// pick the colorattribute k you want
SetConsoleTextAttribute(hConsole, k);
cout << k << " I want to be nice today!" << endl;
}
cin.get(); // wait
return 0;
}
dukiduki 0 Newbie Poster
No it doesent :( VS report me the same error.
problem is i don't know C++...
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
What exactly is the error you are getting ? The code seems to be perfectly alright and working so I guess the problem must be the way you have configured you IDE or with the project settings.
Post the kind of settings you used while creating the project along with the detailed error messages.
John A 1,896 Vampirical Lurker Team Colleague
Make sure that the file you created has a .cpp extension to it, or else the compiler won't recognize the code as C++.
And do what ~s.o.s~ said.
dukiduki 0 Newbie Poster
What exactly is the error you are getting ? The code seems to be perfectly alright and working so I guess the problem must be the way you have configured you IDE or with the project settings.
Post the kind of settings you used while creating the project along with the detailed error messages.
Well i start microsoft visual c ++, then go to file, then i start new win32 console application, then new text file with .c extension.
I understand that yours code is ok, but i need code which will work with .c extension. I'm not alow to use .cpp
I find one function which work (the same as you posted), but VS repot me an warning that i need some conversion but i don't know wich.
#include <stdio.h>
#include <string.h>
#include <windows.h>
#define MAX 20
void promeni_boju (int boja){
HANDLE Konzola=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(Konzola,boja);
}
int provera (char *a,char *b){
if (strcmp(a,b)==0)
return 1;
else
return 0;
}
int provera1 (char *a, char *c){
if(strcmp(a,c)==0)
return 1;
else
return 0;
}
int provera2 (char *a, char *d){
if (strcmp(a,d)==0)
return 1;
else
return 0;
}
int main() {
char rec[MAX];
char *string={"student"};
char *string1={"srce"};
char *string2={"mace"};
char izbor[2];
do{
promeni_boju(10);
printf("\nUnesite rec\n");
scanf("%s",&rec);
if((provera(rec,string))||(provera1(rec,string1))|| (provera2(rec,string2)))
printf("\n Pogodili ste\n");
else
printf(" \nNiste pogodili\n");
printf(" \nZa nastavak unesite \"da\"\n");
scanf("%s",&izbor);
}while(izbor[0]=='d'&& izbor[1]=='a');
system("pause");
return 0;
}
And i have another kind of problem... See now i open my project to copy my code here and build project again and i don't have any warnings... So i don't know is that VS make me some probs or my code is wrong...
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
Your code is working in my case, but some of the problems which you say are appearing as warnings are :
1) scanf("%s",&rec);
The scanf
function requires the address of the variable as its second parameter. Since the name of the array is a pointer to its first element or holds the address of the array, you need only to supply rec. Remove the &
sign which you have placed in front of it.
2) scanf("%s",&izbor);
The same problem exists here.
3) Don't use system("pause")
for pausing the program. Better use getchar()
which is more poratble and more meaningful in this context.
4. Why the three functions which do exactly the same thing i.e. comparing two strings or I would rather say why a separate function for string comparision when strcmp()
does the job well ?
dukiduki 0 Newbie Poster
I will try that... But we use the most function scanf.
This code u saw is just a practise with pointers, it was important to work, nothing more.
That with system pause i don't understand. The function for color I copy-paste. Remain of the code i wrote. Because of that i come here for some explenation for that function, it was the only one whic work, but i dont have any warnings for my code, onlu because of that function for color.
John A 1,896 Vampirical Lurker Team Colleague
That with system pause i don't understand.
Think of it this way: system() calls a command. In this case, you're calling the pause command.
How many platforms will support this? Exactly the same amount as the operating systems that have a "PAUSE" command in their path. Which means it's basically 1, which is Windows.
It's also very slow, because you have to tell the operating system to run another program just to pause yours - not good.
getchar() is fast because it doesn't use call another program, and it's portable - guaranteed to work on all platforms. So there's no need to use system("PAUSE").
But yeah, your code should work.
dwks 149 Posting Whiz in Training
You might actually be getting a warning where you call system(), because system()'s prototype is in <stdlib.h>, which you haven't included.
char izbor[2];
You can't expect that string to be able to store "da\0", which is three characters. Remember, you have to leave space for the NULL.
Even if you do declare the array to have space for three characters (2 chars + NULL), what's to stop the user from entering ten characters, or a thousand? scanf() doesn't know how big you've made your string and assumes that it's big enough to store whatever the user has entered, which might not be the case. If it isn't big enough, you have a buffer overflow.
Use fgets() to read a string from the user if you want to avoid buffer overflows. It takes as a parameter the size of the string, so it knows how many characters it can store.
fgets() doesn't remove the newline entered, so you must remove it yourself if you don't want it.
/* Supremely annoying program that you have to type "cookie" to exit */
#include <stdio.h> /* for fgets(), printf(), BUFSIZ */
#include <string.h> /* for strcmp() */
int main(void) {
char buffer[BUFSIZ], *p; /* BUFSIZ is a reasonable size for a buffer, usually about 512 */
do { /* forever loop */
printf("cookie: ");
fgets(buffer, sizeof(buffer), stdin); /* read a line from stdin */
if((p = strchr(buffer, '\n'))) *p = 0; /* remove the newline, if it is present */
} while(strcmp(buffer, "cookie"));
return 0;
}
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.