Problems Faced By Beginners In C/C++
This post is targeted towards the students of 1st year who enter in the college and are new to computers. Generally, they learn how to program in C / C++, how to compile a source code for the first time in college. At times they face problems while working with the programming langauge which they find difficult to sort out.
Let's discuss most common problems students face while working on C / C++.
1. "Unable to open include file 'IOSTREAM.H'
This error is caused if the path is set wrong and even if your file is present in the correct directory. to resolve this error the user should go to OPTIONS>DIRECTORIES and provide the correct and full path name of header (.h) files. Usually, they are located in the folder "INCLUDE" in the main C/ CPP folder.
2. Some of the readers might have tried to use graphics in C, and got the following error : "Graphics error: Device driver file not found (EGAVGA.BGI) Press any key to halt".
To resolve this issue, user can set the path of EGAVGA.BGI file in initgraph section, usually this BGI file is located under the <main folder>\BGI directory.
initgraph(&gdriver,&gmode,"F:\\TC\\BGI");
Note the double ‘\’ in the path, gdriver is the driver we are using and gmode is the mode in which we are working. In our case, we have <main folder> on F:\ so we set that path as “F:\\TC\\BGI”.
Another way to solve this problem, works only for the current session but is quick and easy to follow.
initgraph(&gdriver,&gmode,””);
Next, just go to FILE>CHANGE DIRECTORY and change the directory to your BGI directory and graphics shall work fine for the current session.
3. For the users who have used graphics in C/C++ must be knowing that we can only use 640*480 resolution or can work only in VGA mode by default, but there is also a way we can use better resolution. Even we can use 1024 *768 resolution in Turbo C.
Download file SVGA256.BGI, which is device driver file (can be found easily on the web) and then install the display driver while running the program, that can be done easily by using below method :
Writing a function (keep it outside the main function)
int huge mode{return(4);}
installuserdriver(“SVGA256”,mode);
4. You must have used functions in programming and surely have passed parameters in that, ever thought of passing arguments to main()?
void main(int argc, char *argv[])
It's simple, argc is a integer which will count the number of arguments in your program and argv is array of pointer to strings. It will store different arguments in it. While working in dos or command line we will give the following command.
C:\>prog01.exe arguments to main
In this total arguments to program are 4 in number that will be stored in argc.
argv[0]=prog01.exe
argv[1]=arguments
argv[2]=to
argv[3]=main
We can change variable name to anything, however, data type should be same.
5. By using C, is it possible to shutdown your PC or delete temporary files? Here we need to access dos commands from a C program and it can be done using function named as system() defined in STDLIB.H
Now to shutdown, you can use the below command:
“shutdown.exe –s –t xx” , where –s stands for shut down, -t stands for the time before shutting down.
Let's discuss most common problems students face while working on C / C++.
1. "Unable to open include file 'IOSTREAM.H'
This error is caused if the path is set wrong and even if your file is present in the correct directory. to resolve this error the user should go to OPTIONS>DIRECTORIES and provide the correct and full path name of header (.h) files. Usually, they are located in the folder "INCLUDE" in the main C/ CPP folder.
2. Some of the readers might have tried to use graphics in C, and got the following error : "Graphics error: Device driver file not found (EGAVGA.BGI) Press any key to halt".
To resolve this issue, user can set the path of EGAVGA.BGI file in initgraph section, usually this BGI file is located under the <main folder>\BGI directory.
initgraph(&gdriver,&gmode,"F:\\TC\\BGI");
Note the double ‘\’ in the path, gdriver is the driver we are using and gmode is the mode in which we are working. In our case, we have <main folder> on F:\ so we set that path as “F:\\TC\\BGI”.
Another way to solve this problem, works only for the current session but is quick and easy to follow.
initgraph(&gdriver,&gmode,””);
Next, just go to FILE>CHANGE DIRECTORY and change the directory to your BGI directory and graphics shall work fine for the current session.
3. For the users who have used graphics in C/C++ must be knowing that we can only use 640*480 resolution or can work only in VGA mode by default, but there is also a way we can use better resolution. Even we can use 1024 *768 resolution in Turbo C.
Download file SVGA256.BGI, which is device driver file (can be found easily on the web) and then install the display driver while running the program, that can be done easily by using below method :
Writing a function (keep it outside the main function)
int huge mode{return(4);}
installuserdriver(“SVGA256”,mode);
4. You must have used functions in programming and surely have passed parameters in that, ever thought of passing arguments to main()?
void main(int argc, char *argv[])
It's simple, argc is a integer which will count the number of arguments in your program and argv is array of pointer to strings. It will store different arguments in it. While working in dos or command line we will give the following command.
C:\>prog01.exe arguments to main
In this total arguments to program are 4 in number that will be stored in argc.
argv[0]=prog01.exe
argv[1]=arguments
argv[2]=to
argv[3]=main
We can change variable name to anything, however, data type should be same.
5. By using C, is it possible to shutdown your PC or delete temporary files? Here we need to access dos commands from a C program and it can be done using function named as system() defined in STDLIB.H
Now to shutdown, you can use the below command:
“shutdown.exe –s –t xx” , where –s stands for shut down, -t stands for the time before shutting down.
That's all folks, however, there are numerous other things in C to learn and the more you know them, the more you will love C. Share such similar tricks in the comments below.