how to solve unterminated ifndef? [closed] - c

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 months ago.
Improve this question
How can I solve the error: unterminated #ifndef when am trying to use header files with my defined functions in C ?
In file included from test.c:1:
main.h:1: error: unterminated #ifndef
1 | # ifndef _MAIN_H_
|
this is the code
# ifndef _MAIN_H_
# ifdef _MAIN_H_
int now(void);
# endif
~
I though #endif solves it all but failed.

The #ifdef should be a #define for you to have working #include guard. As originally written the #ifndef is missing the matching #endif.
Symbols that start with underscore followed by an uppercase letter are reserved (6.4.2.1). Use MAIN_H instead.
You could also use #pragma once which is a non-standard, but widely supported, alternative to the include guard.
Leave out the ~ of the code listing as it's vi's EOF marker and not part of your header file.

Related

main.c:16:9: error: stray '\32' in program in C [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I am trying an example from the GNU C Programming Tutorial (page 93) that uses a few of the math library routines listed.
#include <stdio.h>
#include <math.h>
int main() {
double my_pi;
my_pi = 4 * atan(1.0);
/* Print the value of pi, to 32 digits */
printf("my_pi = %.32f\n", my_pi);
/* Print value of pi from math library, to 32 digits */
printf("M_PI = %.32f\n", M_PI);
return 0;
}
When I compile the file 'main.c' using MinGw using the command
gcc main.c -o main -lm
It gives the following error:
main.c:16:9: error: stray '\32' in program
16 : }
: ^
Error occurred because of using Turbo C to edit 'main.c' which adds → character at the end of the curly brackets. That is why compilation fails in MinGw..
The code \32 is an ASCII control character ^Z aka EOF - the End-Of-File (see https://en.wikipedia.org/wiki/End-of-file#EOF_character). It was appended at the end of the text file with some (DOS-like?) editing tool – or maybe you copied a source code and pasted it through some shell command to a file, which resulted in appending the EOF byte.
Try using some other editing tool to strip the last byte from your main.c file. Maybe adding a newline after the closing bracket would be good start.

gcc: –Wall: No such file or directory (In C) [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
The command line that I'm suppose to compile my program is:
gcc –Wall –o prs process.c
I'm getting these errors:
gcc: –Wall: No such file or directory
gcc: –o: No such file or directory
gcc: prs: No such file or directory
I'm sure that I'm in the correct directory. It works when I use gcc process.c and it runs perfectly.
My prof requires us to use that command line to compile, so I don't think I should change the compile command.
– is an en dash, which GCC is interpreting as a filename.
You need to use a regular hyphen (-).

GCC link a directory [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I want compile a .c script with the gcc-compiler.
But i need to link a file and a directory. I need to link the file python3.lib and the directory D:\Python33\include.
But the linker doesn't work, here my code:
gcc main.c -lpython3 -l D:\Python33\include
The Error:
main.c:1:20: fatal error: Python.h: No such file or directory
#include <Python.h>
^
compilation terminated.
What is wrong? Thank you for help!
You are passing wrong parameters to gcc.
gcc main.c -L /path/to/lib/file/directory -lpython3 -I D:\Python33\include
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^

How to create my own header file in c++? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I m a new budding programmer.Is it possible for me to create a new header file of my own? Can anyone help me how to create my own header file in c++ with an example ?
Yes, of course you can, but before that you need to learn what header files are and how you can use them properly.
file: yourname.h
#ifndef YOUR_NAME_INCLUDE
#define YOUR_NAME_INCLUDE
/* Your function statement here */
#endif
yourname.cpp
#include <iostream.h>
#include "yourname.h"
/* Your function definition here */
main.cpp
#include <iostream.h>
#include "yourname.h"
/* Your function calling here */
To learn more about header files and include statements, click the link below.
Header tutorial
Yes, you can create your own header file.
Kindly go through thinking in c++ by bruce eckel vol 1.
Just to begin with, a header file is which has extension '.h'/'.hpp'
These files have declaration of user defined data structures and interfaces such has class declaration, function prototypes and etc.
After declaring and storing it into project folder. you need to include this file in .cpp/.c
eg.:
file: myheader.h
#ifndef MYHEADER
#define MYHEADER
......
#endif
file: myclass.cpp
#include <iostream.h>
#include "myheader.h"

C: Problems with preprocessing definition [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I see the following error when compiling...
./src/gettext.h:17:22: fatal error: libintl.h: No such file or directory
So I look at the code and see...
#ifndef NO_GETTEXT
# include <libintl.h>
#else
# ifdef gettext
# undef gettext
# endif
# define gettext(s) (s)
# ifdef ngettext
# undef ngettext
# endif
# define ngettext(s, p, n) ((n == 1) ? (s) : (p))
#endif
I add a file called config.h which I add the following....
#define NO_GETTEXT
But it doesn't seem to have defined it because I still see the error. I am rather new to C so I am not sure what is up. Any help?
Oops should be...
LOCAL_CFLAGS := -DNO_GETTEXT
in my MakeFile

Resources