CFanatic

Go Back   CFanatic > Programming > C Programming

Error while compiling program topic posted under C Programming which is a part of Programming category in CFanatic Forum
Reply
 
Thread Tools Display Modes
  #1  
Old 06-11-2012, 02:18 AM
Member
 
Join Date: Feb 2012
Posts: 38
Thanks: 4
Thanked 0 Times in 0 Posts
ballurohit is on a distinguished road
| More
Error while compiling program

I found error in compiling the file. The program file is annexed.

(B.N.ROHIT)
Kindly have your advice on it early.
Reply With Quote
  #2  
Old 06-11-2012, 05:39 AM
Member
 
Join Date: Feb 2012
Posts: 38
Thanks: 4
Thanked 0 Times in 0 Posts
ballurohit is on a distinguished road
| More
Re: Error while compiling program

There is a compilor error.The copy of the program is annexed.
#include <iostream.h>
#include <stdlib.h>
#include <errno.h>
#ifndef LINE_NUM_H
#define LINE_NUM_H
#include "line_num.h"
int main()

{
int _LINE_NUM;
{
cout<<"This is the line number:"<<_LINE_NUM <<endl;
cout<<"line number is:"<<_LINE_NUM"," <<FILE NAME <<endl;
cout<<"The Compiler gives a _cplusplus value of:";
cin>>_LINE_NUM;
return 0;
}
}
#endif


Pl. have some advice.
Reply With Quote
  #3  
Old 06-11-2012, 12:56 PM
hobbyist's Avatar
Senior Member
 
Join Date: Jan 2012
Posts: 122
Thanks: 5
Thanked 49 Times in 42 Posts
hobbyist will become famous soon enough
| More
Re: Error while compiling program

What compiler are you using?? What is declared within line_num.h?? What compiler errors are being generated??

Code:
 cout<<"This is the line number:"<<_LINE_NUM <<endl;
_LINE_NUM hasn't been initialized yet

Code:
 cout<<"line number is:"<<_LINE_NUM"," <<FILE NAME <<endl;
you're missing << between _LINE_NUM and "," and FILE NAME has a white space.

really old compilers don't have the std namespace and use the old style headers. If you're using a newer modern compiler, change the includes

Code:
#include <iostream>
#include <cstdlib>
#include <cerrno>

using namespace std;
...
Reply With Quote
The Following User Says Thank You to hobbyist For This Useful Post:
shabbir (06-11-2012)
  #4  
Old 06-12-2012, 01:59 AM
Member
 
Join Date: Feb 2012
Posts: 38
Thanks: 4
Thanked 0 Times in 0 Posts
ballurohit is on a distinguished road
| More
Re: Error while compiling program

I am using Turbo C compiler.In line_num.h I have used " Int main() { int_LINE_NUM;
return 0;
{
Actually I have not initialized the variable. That is my mistake.
Reply With Quote
  #5  
Old 06-12-2012, 05:07 PM
hobbyist's Avatar
Senior Member
 
Join Date: Jan 2012
Posts: 122
Thanks: 5
Thanked 49 Times in 42 Posts
hobbyist will become famous soon enough
| More
Re: Error while compiling program

The header file, line_num.h, should only be used for declaring typedefs, classes, global variables (if any), and function prototypes. function main() belongs in a source file such as .c or .cpp

I'm not exactly sure what you're wanting to do. If you're wanting to print the macros __LINE__, __FILE__, and _cplusplus, then maybe try

Code:
#ifdef _cplusplus
#define is_cpp 1
#else
#define is_cpp 0
#endif

cout << "this file is: " << __FILE__
      << "\n"
      << "this line is: " << __LINE__
      << "\n"
      << "_cplusplus defined is: " << is_cpp;
_cplusplus doesn't seem to exist on the compiler I'm currently using. :|
Reply With Quote
  #6  
Old 06-12-2012, 11:39 PM
Member
 
Join Date: Feb 2012
Posts: 38
Thanks: 4
Thanked 0 Times in 0 Posts
ballurohit is on a distinguished road
| More
Re: Error while compiling program

I desire to place the header file into the .cpp file for knowing the error line number exactly and nothing else.
Reply With Quote
  #7  
Old 06-13-2012, 11:53 AM
hobbyist's Avatar
Senior Member
 
Join Date: Jan 2012
Posts: 122
Thanks: 5
Thanked 49 Times in 42 Posts
hobbyist will become famous soon enough
| More
Re: Error while compiling program

you'll need to trap any errors and take steps programmatically to rectify/report them. I don't know if turbo has try, catch, and throw or not but you might mill over the reference to see how they work. If your application is a debug build, you might also look into using assert. Lastly, you might try a macro in your header... maybe something like

note: \ is intentional when spanning multiple lines; without it, the compiler will protest.

Code:
// take 3 arguments, the line near the error, 
// the source file where the error occured, and
// whether or not to clear the input stream

#define errorState(errline, errfile, errflag) { \
   if(errflag == true) { \
      cin.clear(); \
      while(cin.get() != '\n'){} \
   } \
   cout << "error on line: " \
          << errline \
          << "\nin file: " \
          << errfile; \
} \
in your cpp file, you'd do something like

Code:
int n;
cout << "Enter an integer: ";
if(!(cin >> n)) 
   errorState(__LINE__, __FILE__, true);
hope that helps
Reply With Quote
  #8  
Old 06-16-2012, 11:32 PM
Member
 
Join Date: Feb 2012
Posts: 38
Thanks: 4
Thanked 0 Times in 0 Posts
ballurohit is on a distinguished road
| More
Re: Error while compiling program

what is that \ mark in the suggested program!
Reply With Quote
  #9  
Old 06-20-2012, 12:22 AM
hobbyist's Avatar
Senior Member
 
Join Date: Jan 2012
Posts: 122
Thanks: 5
Thanked 49 Times in 42 Posts
hobbyist will become famous soon enough
| More
Re: Error while compiling program

it is required to span multiple lines

Code:
printf("hello \
         world"); // okay
printf("hello
         world"); // compiler error
in the #define errorState macro, \ is needed because the code spans multiple lines; that's all.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
compiling coding in c Richa Introduce yourself 2 02-29-2012 07:07 AM
Error in the program & I need some programs. Can you help me wd.hamaden C Programming 2 07-28-2011 04:17 AM
help needed : poblem here is that program shows no error while compiling and does not psal_dun C Programming 2 05-11-2011 10:13 PM
Warning messages compiling C program puth C Programming 0 09-07-2010 05:12 PM
Error in compiling creative C Programming 1 03-20-2010 11:58 PM



Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2010, Crawlability, Inc.