I have the code
void switchstate(gamestates state) --line 53
{ --line 54
switch(state)
case state_title:
title();
break;
case state_about:
break;
case state_game:
break;
case state_battle:
break;
}
enum gamestates
{
state_title, state_about, state_game, state_battle,
};
int main( int argc, char* args[] )
{
gamestates currentstate = state_title;
startup();
load_resources();
switchstate(currentstate); --line 169
return 0;
}
and when I try to compile I get the errors:
\main.cpp:53: error: 'gamestates' was not declared in this scope
\main.cpp:54: error: expected ',' or ';' before '{' token
\main.cpp: In function 'int SDL_main(int, char**)':
\main.cpp:169: error: 'switchstate' cannot be used as a function
I've never used enumerations before so I'm confused on what's not working.
Generally, errors of the "<symbol> not in scope" means the compiler hasn't seen <symbol> yet. So move the declaration of gamestates to before void switchstate(...), either via an earlier #include or just moving it up in the file.
C and C++ compile from top to bottom, so symbols must be declared before they are used.
Move the declaration of the enum so it's above the switchstate function. That should do the trick. C++ is very particular about the order things are declared.
Move the enum gamestates line up in the file, before switchstate.
You may want to define the enum before the switchstate function.
In C++, you have to declare all of your types before you can refer to them. Here, you're declaring your enum after the switchstate function, so when the C++ compiler reads switchstate, it sees you refer to a type it doesn't know yet, and makes an error. If you move the enum declaration before switchstate, you should be fine.
In general, you should put declarations at the top of your file, or in seperate header files which you include at the top of the file.
Try moving definition of gamestates above the switchstate function definition.
Related
What are undeclared identifier errors? What are common causes and how do I fix them?
Example error texts:
For the Visual Studio compiler: error C2065: 'cout' : undeclared identifier
For the GCC compiler: 'cout' undeclared (first use in this function)
They most often come from forgetting to include the header file that contains the function declaration, for example, this program will give an 'undeclared identifier' error:
Missing header
int main() {
std::cout << "Hello world!" << std::endl;
return 0;
}
To fix it, we must include the header:
#include <iostream>
int main() {
std::cout << "Hello world!" << std::endl;
return 0;
}
If you wrote the header and included it correctly, the header may contain the wrong include guard.
To read more, see http://msdn.microsoft.com/en-us/library/aa229215(v=vs.60).aspx.
Misspelled variable
Another common source of beginner's error occur when you misspelled a variable:
int main() {
int aComplicatedName;
AComplicatedName = 1; /* mind the uppercase A */
return 0;
}
Incorrect scope
For example, this code would give an error, because you need to use std::string:
#include <string>
int main() {
std::string s1 = "Hello"; // Correct.
string s2 = "world"; // WRONG - would give error.
}
Use before declaration
void f() { g(); }
void g() { }
g has not been declared before its first use. To fix it, either move the definition of g before f:
void g() { }
void f() { g(); }
Or add a declaration of g before f:
void g(); // declaration
void f() { g(); }
void g() { } // definition
stdafx.h not on top (VS-specific)
This is Visual Studio-specific. In VS, you need to add #include "stdafx.h" before any code. Code before it is ignored by the compiler, so if you have this:
#include <iostream>
#include "stdafx.h"
The #include <iostream> would be ignored. You need to move it below:
#include "stdafx.h"
#include <iostream>
Feel free to edit this answer.
Consider a similar situation in conversation. Imagine your friend says to you, "Bob is coming over for dinner," and you have no idea who Bob is. You're going to be confused, right? Your friend should have said, "I have a work colleague called Bob. Bob is coming over for dinner." Now Bob has been declared and you know who your friend is talking about.
The compiler emits an 'undeclared identifier' error when you have attempted to use some identifier (what would be the name of a function, variable, class, etc.) and the compiler has not seen a declaration for it. That is, the compiler has no idea what you are referring to because it hasn't seen it before.
If you get such an error in C or C++, it means that you haven't told the compiler about the thing you are trying to use. Declarations are often found in header files, so it likely means that you haven't included the appropriate header. Of course, it may be that you just haven't remembered to declare the entity at all.
Some compilers give more specific errors depending on the context. For example, attempting to compile X x; where the type X has not been declared with clang will tell you "unknown type name X". This is much more useful because you know it's trying to interpret X as a type. However, if you have int x = y;, where y is not yet declared, it will tell you "use of undeclared identifier y" because there is some ambiguity about what exactly y might represent.
In C and C++ all names have to be declared before they are used. If you try to use the name of a variable or a function that hasn't been declared you will get an "undeclared identifier" error.
However, functions are a special case in C (and in C only) in that you don't have to declare them first. The C compiler will the assume the function exists with the number and type of arguments as in the call. If the actual function definition does not match that you will get another error. This special case for functions does not exist in C++.
You fix these kind of errors by making sure that functions and variables are declared before they are used. In the case of printf you need to include the header file <stdio.h> (or <cstdio> in C++).
For standard functions, I recommend you check e.g. this reference site, and search for the functions you want to use. The documentation for each function tells you what header file you need.
I had the same problem with a custom class, which was defined in a namespace. I tried to use the class without the namespace, causing the compiler error "identifier "MyClass" is undefined".
Adding
using namespace <MyNamespace>
or using the class like
MyNamespace::MyClass myClass;
solved the problem.
These error meassages
1.For the Visual Studio compiler: error C2065: 'printf' : undeclared identifier
2.For the GCC compiler: `printf' undeclared (first use in this function)
mean that you use name printf but the compiler does not see where the name was declared and accordingly does not know what it means.
Any name used in a program shall be declared before its using. The compiler has to know what the name denotes.
In this particular case the compiler does not see the declaration of name printf . As we know (but not the compiler) it is the name of standard C function declared in header <stdio.h> in C or in header <cstdio> in C++ and placed in standard (std::) and global (::) (not necessarily) name spaces.
So before using this function we have to provide its name declaration to the compiler by including corresponding headers.
For example
C:
#include <stdio.h>
int main( void )
{
printf( "Hello World\n" );
}
C++:
#include <cstdio>
int main()
{
std::printf( "Hello World\n" );
// or printf( "Hello World\n" );
// or ::printf( "Hello World\n" );
}
Sometimes the reason of such an error is a simple typo. For example let's assume that you defined function PrintHello
void PrintHello()
{
std::printf( "Hello World\n" );
}
but in main you made a typo and instead of PrintHello you typed printHello with lower case letter 'p'.
#include <cstdio>
void PrintHello()
{
std::printf( "Hello World\n" );
}
int main()
{
printHello();
}
In this case the compiler will issue such an error because it does not see the declaration of name printHello. PrintHello and printHello are two different names one of which was declared and other was not declared but used in the body of main
It happened to me when the auto formatter in a visual studio project sorted my includes after which the pre compiled header was not the first include anymore.
In other words. If you have any of these:
#include "pch.h"
or
#include <stdio.h>
or
#include <iostream>
#include "stdafx.h"
Put it at the start of your file.
If your clang formatter is sorting the files automatically, try putting an enter after the pre compiled header. If it is on IBS_Preserve it will sort each #include block separately.
#include "pch.h" // must be first
#include "bar.h" // next block
#include "baz.h"
#include "foo.h"
More info at
Compiler Error C2065
A C++ identifier is a name used to identify a variable, function, class, module, or any other user-defined item. In C++ all names have to be declared before they are used. If you try to use the name of a such that hasn't been declared you will get an "undeclared identifier" compile-error.
According to the documentation, the declaration of printf() is in cstdio i.e. you have to include it, before using the function.
Another possible situation: accessing parent (a template class) member in a template class.
Fix method: using the parent class member by its full name (by prefixing this-> or parentClassName:: to the name of the member).
see: templates: parent class member variables not visible in inherited class
one more case where this issue can occur,
if(a==b)
double c;
getValue(c);
here, the value is declared in a condition and then used outside it.
It is like Using the function without declaring it. header file will contain the
function printf(). Include the header file in your program this is the solution for that.
Some user defined functions may also through error when not declared before using it. If
it is used globally no probs.
Most of the time, if you are very sure you imported the library in question, Visual Studio will guide you with IntelliSense.
Here is what worked for me:
Make sure that #include "stdafx.h" is declared first, that is, at the top of all of your includes.
Every undeclared variable in c error comes because the compiler is not able to find it in the project. One can include the external (header) file of the library in which the variable is defined. Hence in your question, you require <stdio.h>, that is a standard input output file, which describes printf(), functionality.
According to the documentation, the declaration of fprintf() is in i.e. you have to include it, before using the function.
Check if you are importing the same packages in your .m and in your .h
Example given: I had this very problem with the init method and it was caused by missing the "#import " on the .m file
I am in the process of creating a C wrapper around a C++ library.
One common mistake to make while doing this is having a function declaration and definition that do not match for some reason (typo, renames, argument got added/removed, etc).
For example:
// enabledata.h
MDS_C_API const char* motek_mds_enable_data_get_enable_command_name();
// enabledata.cpp
const char* motek_mds_enable_data_enable_command_name() { ... }
The names do not match, but because of the lack of scope for these functions, it will not result in any compile errors, and will only show up much later down the line as a link error.
I want the compiler to help me find these errors by using the global scope operator like so:
const char* ::motek_mds_enable_data_get_disable_command_name() { ... }
This will now show up as a compile error if the function has not been declared yet, which is exactly what I want.
However, this does not work when the function returns a typedef:
int32_t ::motek_mds_enable_data_is_enabled(const Data* a_Data) { ... }
This will result in an attempt to use int32_t as a scope, which of course results in an error:
left of '::' must be a class/struct/union
Are there any ways to make this work? Better alternatives are also welcome of course.
I am currently using Visual Studio 2015 Update 2.
You can always parenthesize the declarator-id:
int32_t (::motek_mds_enable_data_is_enabled)(const Data* a_Data) { ... }
// ^ ^
What are undeclared identifier errors? What are common causes and how do I fix them?
Example error texts:
For the Visual Studio compiler: error C2065: 'cout' : undeclared identifier
For the GCC compiler: 'cout' undeclared (first use in this function)
They most often come from forgetting to include the header file that contains the function declaration, for example, this program will give an 'undeclared identifier' error:
Missing header
int main() {
std::cout << "Hello world!" << std::endl;
return 0;
}
To fix it, we must include the header:
#include <iostream>
int main() {
std::cout << "Hello world!" << std::endl;
return 0;
}
If you wrote the header and included it correctly, the header may contain the wrong include guard.
To read more, see http://msdn.microsoft.com/en-us/library/aa229215(v=vs.60).aspx.
Misspelled variable
Another common source of beginner's error occur when you misspelled a variable:
int main() {
int aComplicatedName;
AComplicatedName = 1; /* mind the uppercase A */
return 0;
}
Incorrect scope
For example, this code would give an error, because you need to use std::string:
#include <string>
int main() {
std::string s1 = "Hello"; // Correct.
string s2 = "world"; // WRONG - would give error.
}
Use before declaration
void f() { g(); }
void g() { }
g has not been declared before its first use. To fix it, either move the definition of g before f:
void g() { }
void f() { g(); }
Or add a declaration of g before f:
void g(); // declaration
void f() { g(); }
void g() { } // definition
stdafx.h not on top (VS-specific)
This is Visual Studio-specific. In VS, you need to add #include "stdafx.h" before any code. Code before it is ignored by the compiler, so if you have this:
#include <iostream>
#include "stdafx.h"
The #include <iostream> would be ignored. You need to move it below:
#include "stdafx.h"
#include <iostream>
Feel free to edit this answer.
Consider a similar situation in conversation. Imagine your friend says to you, "Bob is coming over for dinner," and you have no idea who Bob is. You're going to be confused, right? Your friend should have said, "I have a work colleague called Bob. Bob is coming over for dinner." Now Bob has been declared and you know who your friend is talking about.
The compiler emits an 'undeclared identifier' error when you have attempted to use some identifier (what would be the name of a function, variable, class, etc.) and the compiler has not seen a declaration for it. That is, the compiler has no idea what you are referring to because it hasn't seen it before.
If you get such an error in C or C++, it means that you haven't told the compiler about the thing you are trying to use. Declarations are often found in header files, so it likely means that you haven't included the appropriate header. Of course, it may be that you just haven't remembered to declare the entity at all.
Some compilers give more specific errors depending on the context. For example, attempting to compile X x; where the type X has not been declared with clang will tell you "unknown type name X". This is much more useful because you know it's trying to interpret X as a type. However, if you have int x = y;, where y is not yet declared, it will tell you "use of undeclared identifier y" because there is some ambiguity about what exactly y might represent.
In C and C++ all names have to be declared before they are used. If you try to use the name of a variable or a function that hasn't been declared you will get an "undeclared identifier" error.
However, functions are a special case in C (and in C only) in that you don't have to declare them first. The C compiler will the assume the function exists with the number and type of arguments as in the call. If the actual function definition does not match that you will get another error. This special case for functions does not exist in C++.
You fix these kind of errors by making sure that functions and variables are declared before they are used. In the case of printf you need to include the header file <stdio.h> (or <cstdio> in C++).
For standard functions, I recommend you check e.g. this reference site, and search for the functions you want to use. The documentation for each function tells you what header file you need.
I had the same problem with a custom class, which was defined in a namespace. I tried to use the class without the namespace, causing the compiler error "identifier "MyClass" is undefined".
Adding
using namespace <MyNamespace>
or using the class like
MyNamespace::MyClass myClass;
solved the problem.
These error meassages
1.For the Visual Studio compiler: error C2065: 'printf' : undeclared identifier
2.For the GCC compiler: `printf' undeclared (first use in this function)
mean that you use name printf but the compiler does not see where the name was declared and accordingly does not know what it means.
Any name used in a program shall be declared before its using. The compiler has to know what the name denotes.
In this particular case the compiler does not see the declaration of name printf . As we know (but not the compiler) it is the name of standard C function declared in header <stdio.h> in C or in header <cstdio> in C++ and placed in standard (std::) and global (::) (not necessarily) name spaces.
So before using this function we have to provide its name declaration to the compiler by including corresponding headers.
For example
C:
#include <stdio.h>
int main( void )
{
printf( "Hello World\n" );
}
C++:
#include <cstdio>
int main()
{
std::printf( "Hello World\n" );
// or printf( "Hello World\n" );
// or ::printf( "Hello World\n" );
}
Sometimes the reason of such an error is a simple typo. For example let's assume that you defined function PrintHello
void PrintHello()
{
std::printf( "Hello World\n" );
}
but in main you made a typo and instead of PrintHello you typed printHello with lower case letter 'p'.
#include <cstdio>
void PrintHello()
{
std::printf( "Hello World\n" );
}
int main()
{
printHello();
}
In this case the compiler will issue such an error because it does not see the declaration of name printHello. PrintHello and printHello are two different names one of which was declared and other was not declared but used in the body of main
It happened to me when the auto formatter in a visual studio project sorted my includes after which the pre compiled header was not the first include anymore.
In other words. If you have any of these:
#include "pch.h"
or
#include <stdio.h>
or
#include <iostream>
#include "stdafx.h"
Put it at the start of your file.
If your clang formatter is sorting the files automatically, try putting an enter after the pre compiled header. If it is on IBS_Preserve it will sort each #include block separately.
#include "pch.h" // must be first
#include "bar.h" // next block
#include "baz.h"
#include "foo.h"
More info at
Compiler Error C2065
A C++ identifier is a name used to identify a variable, function, class, module, or any other user-defined item. In C++ all names have to be declared before they are used. If you try to use the name of a such that hasn't been declared you will get an "undeclared identifier" compile-error.
According to the documentation, the declaration of printf() is in cstdio i.e. you have to include it, before using the function.
Another possible situation: accessing parent (a template class) member in a template class.
Fix method: using the parent class member by its full name (by prefixing this-> or parentClassName:: to the name of the member).
see: templates: parent class member variables not visible in inherited class
one more case where this issue can occur,
if(a==b)
double c;
getValue(c);
here, the value is declared in a condition and then used outside it.
It is like Using the function without declaring it. header file will contain the
function printf(). Include the header file in your program this is the solution for that.
Some user defined functions may also through error when not declared before using it. If
it is used globally no probs.
Most of the time, if you are very sure you imported the library in question, Visual Studio will guide you with IntelliSense.
Here is what worked for me:
Make sure that #include "stdafx.h" is declared first, that is, at the top of all of your includes.
Every undeclared variable in c error comes because the compiler is not able to find it in the project. One can include the external (header) file of the library in which the variable is defined. Hence in your question, you require <stdio.h>, that is a standard input output file, which describes printf(), functionality.
According to the documentation, the declaration of fprintf() is in i.e. you have to include it, before using the function.
Check if you are importing the same packages in your .m and in your .h
Example given: I had this very problem with the init method and it was caused by missing the "#import " on the .m file
What are undeclared identifier errors? What are common causes and how do I fix them?
Example error texts:
For the Visual Studio compiler: error C2065: 'cout' : undeclared identifier
For the GCC compiler: 'cout' undeclared (first use in this function)
They most often come from forgetting to include the header file that contains the function declaration, for example, this program will give an 'undeclared identifier' error:
Missing header
int main() {
std::cout << "Hello world!" << std::endl;
return 0;
}
To fix it, we must include the header:
#include <iostream>
int main() {
std::cout << "Hello world!" << std::endl;
return 0;
}
If you wrote the header and included it correctly, the header may contain the wrong include guard.
To read more, see http://msdn.microsoft.com/en-us/library/aa229215(v=vs.60).aspx.
Misspelled variable
Another common source of beginner's error occur when you misspelled a variable:
int main() {
int aComplicatedName;
AComplicatedName = 1; /* mind the uppercase A */
return 0;
}
Incorrect scope
For example, this code would give an error, because you need to use std::string:
#include <string>
int main() {
std::string s1 = "Hello"; // Correct.
string s2 = "world"; // WRONG - would give error.
}
Use before declaration
void f() { g(); }
void g() { }
g has not been declared before its first use. To fix it, either move the definition of g before f:
void g() { }
void f() { g(); }
Or add a declaration of g before f:
void g(); // declaration
void f() { g(); }
void g() { } // definition
stdafx.h not on top (VS-specific)
This is Visual Studio-specific. In VS, you need to add #include "stdafx.h" before any code. Code before it is ignored by the compiler, so if you have this:
#include <iostream>
#include "stdafx.h"
The #include <iostream> would be ignored. You need to move it below:
#include "stdafx.h"
#include <iostream>
Feel free to edit this answer.
Consider a similar situation in conversation. Imagine your friend says to you, "Bob is coming over for dinner," and you have no idea who Bob is. You're going to be confused, right? Your friend should have said, "I have a work colleague called Bob. Bob is coming over for dinner." Now Bob has been declared and you know who your friend is talking about.
The compiler emits an 'undeclared identifier' error when you have attempted to use some identifier (what would be the name of a function, variable, class, etc.) and the compiler has not seen a declaration for it. That is, the compiler has no idea what you are referring to because it hasn't seen it before.
If you get such an error in C or C++, it means that you haven't told the compiler about the thing you are trying to use. Declarations are often found in header files, so it likely means that you haven't included the appropriate header. Of course, it may be that you just haven't remembered to declare the entity at all.
Some compilers give more specific errors depending on the context. For example, attempting to compile X x; where the type X has not been declared with clang will tell you "unknown type name X". This is much more useful because you know it's trying to interpret X as a type. However, if you have int x = y;, where y is not yet declared, it will tell you "use of undeclared identifier y" because there is some ambiguity about what exactly y might represent.
In C and C++ all names have to be declared before they are used. If you try to use the name of a variable or a function that hasn't been declared you will get an "undeclared identifier" error.
However, functions are a special case in C (and in C only) in that you don't have to declare them first. The C compiler will the assume the function exists with the number and type of arguments as in the call. If the actual function definition does not match that you will get another error. This special case for functions does not exist in C++.
You fix these kind of errors by making sure that functions and variables are declared before they are used. In the case of printf you need to include the header file <stdio.h> (or <cstdio> in C++).
For standard functions, I recommend you check e.g. this reference site, and search for the functions you want to use. The documentation for each function tells you what header file you need.
I had the same problem with a custom class, which was defined in a namespace. I tried to use the class without the namespace, causing the compiler error "identifier "MyClass" is undefined".
Adding
using namespace <MyNamespace>
or using the class like
MyNamespace::MyClass myClass;
solved the problem.
These error meassages
1.For the Visual Studio compiler: error C2065: 'printf' : undeclared identifier
2.For the GCC compiler: `printf' undeclared (first use in this function)
mean that you use name printf but the compiler does not see where the name was declared and accordingly does not know what it means.
Any name used in a program shall be declared before its using. The compiler has to know what the name denotes.
In this particular case the compiler does not see the declaration of name printf . As we know (but not the compiler) it is the name of standard C function declared in header <stdio.h> in C or in header <cstdio> in C++ and placed in standard (std::) and global (::) (not necessarily) name spaces.
So before using this function we have to provide its name declaration to the compiler by including corresponding headers.
For example
C:
#include <stdio.h>
int main( void )
{
printf( "Hello World\n" );
}
C++:
#include <cstdio>
int main()
{
std::printf( "Hello World\n" );
// or printf( "Hello World\n" );
// or ::printf( "Hello World\n" );
}
Sometimes the reason of such an error is a simple typo. For example let's assume that you defined function PrintHello
void PrintHello()
{
std::printf( "Hello World\n" );
}
but in main you made a typo and instead of PrintHello you typed printHello with lower case letter 'p'.
#include <cstdio>
void PrintHello()
{
std::printf( "Hello World\n" );
}
int main()
{
printHello();
}
In this case the compiler will issue such an error because it does not see the declaration of name printHello. PrintHello and printHello are two different names one of which was declared and other was not declared but used in the body of main
It happened to me when the auto formatter in a visual studio project sorted my includes after which the pre compiled header was not the first include anymore.
In other words. If you have any of these:
#include "pch.h"
or
#include <stdio.h>
or
#include <iostream>
#include "stdafx.h"
Put it at the start of your file.
If your clang formatter is sorting the files automatically, try putting an enter after the pre compiled header. If it is on IBS_Preserve it will sort each #include block separately.
#include "pch.h" // must be first
#include "bar.h" // next block
#include "baz.h"
#include "foo.h"
More info at
Compiler Error C2065
A C++ identifier is a name used to identify a variable, function, class, module, or any other user-defined item. In C++ all names have to be declared before they are used. If you try to use the name of a such that hasn't been declared you will get an "undeclared identifier" compile-error.
According to the documentation, the declaration of printf() is in cstdio i.e. you have to include it, before using the function.
Another possible situation: accessing parent (a template class) member in a template class.
Fix method: using the parent class member by its full name (by prefixing this-> or parentClassName:: to the name of the member).
see: templates: parent class member variables not visible in inherited class
one more case where this issue can occur,
if(a==b)
double c;
getValue(c);
here, the value is declared in a condition and then used outside it.
It is like Using the function without declaring it. header file will contain the
function printf(). Include the header file in your program this is the solution for that.
Some user defined functions may also through error when not declared before using it. If
it is used globally no probs.
Most of the time, if you are very sure you imported the library in question, Visual Studio will guide you with IntelliSense.
Here is what worked for me:
Make sure that #include "stdafx.h" is declared first, that is, at the top of all of your includes.
Every undeclared variable in c error comes because the compiler is not able to find it in the project. One can include the external (header) file of the library in which the variable is defined. Hence in your question, you require <stdio.h>, that is a standard input output file, which describes printf(), functionality.
According to the documentation, the declaration of fprintf() is in i.e. you have to include it, before using the function.
Check if you are importing the same packages in your .m and in your .h
Example given: I had this very problem with the init method and it was caused by missing the "#import " on the .m file
I got a global object of type "unnamed-struct" and i'm trying to define it. I don't want to pollute my global namespace with such useless type (it will be used only once).
Global.h
extern struct {
int x;
} A;
Is there any correct way to define such object?
I was trying this:
Global.cpp
struct {
int x;
} A = { 0 };
But VS2012 throws "error C2371: 'A' : redefinition; different basic types". Thanks.
One possible solution: create another file Global_A.cpp that does not include Global.h, and define A there. By the equivalent-definition rule this will be valid, as long as the anonymous struct definitions are equivalent.
This is still a bad idea, and most compilers will warn about it e.g. (gcc): warning: non-local variable `<anonymous struct> A' uses anonymous type.
There is no way to do just this simply because it would be error prone: some time in the future someone (probably even you) may want to modify this structure's definition and he might forget to do this in the header and source files accordingly. So you will have to invent a name for this structure and use its name the source file and leave its definition up to the header.
I don't know if this helps you, and this my first post... So take it easy.
I just ran into this issue and what I did was I added a function that manipulates the struct to the file that contained the anonymous struct. That way I can call that function from any file in my project, and it manipulates the values in the struct for me.
Here is an example:
header.c has this anonymous struct:
struct
{
char line1[80];
char line2[80];
char line3[80];
} header;
I want to manipulate those values in "interface.c" because I am making a command line interface in another file. My first instinct was to use an extern, but it seems like adding the following function to header.c is just as good or better (Some people discourage the use of externs when avoidable).
void changeHeaders(char *one, char *two, char *three);
void changeHeaders(char *one, char *two, char *three)
{
strcpy(header.line1, one);
printf("\nHeader 1: %s", header.line1);
strcpy(header.line2, two);
printf("\nHeader 2: %s", header.line2);
strcpy(header.line3, three);
printf("\nHeader 3: %s", header.line3);
}
Now as long as I include the prototype for that function I can manipulate those struct variables from any file by using that function. Hope that helps someone.