C :: How To Share Variable Value From One Source File To Other Header File
Dec 11, 2014
I wanted to share the value of a variable from Sender Program to Receive after program and want to calculate difference between send and receive. After studying Header file concept I program following three.
Now I am struck. How to to compile? I link all these file. I used following method:
Code:
gcc Sender.c -o Sender Sender.h
gcc Receiver.c -o Receiver Student.h
Then I run Sender and after that Receiver.I per my knowledge, Receiver should give difference but it gives error :
Code:
Receiver.c: In function "main":
Receiver.c:10:42: error: "Send" undeclared (first use in this function)
printf(" Total Receive is %d
",Receive-Send);
Code:
Sender.c
#include <stdio.h>
int Send ;
void main(){
[Code] ....
View 2 Replies
ADVERTISEMENT
Jan 30, 2013
My socket.cpp program got error. it showed "socket.h: no such file or directory". I had put my header file (socket.h) in the same place with my source file.
View 1 Replies
View Related
Jul 10, 2013
For example, I have the below files in a project called Calculate :
Source files : Calculate.cpp , Average.cpp (with out main)
Header files : Calculate.h , Average.h
I knew in general, we have to include Average.h to project header file Calculate.h to make it as part of project.
technical difference between adding header file (Average.h) to either project header file (Calculate.h) or project source file (Calculate.cpp) ?
I found no difference in an output. But, there must be technical difference.
View 3 Replies
View Related
Jul 19, 2014
Let's say I am using a library containing classes called class1 and class2 but both classes take three arguments to construct them. eg. class1(int a, int b, int c). and the same for class2
The below is an example of how to lay out the structure in the header and source file if class1 and class2 don't have any arguments in their constructor. But.... I'm not sure how to go about the below to take into account the constructor arguments of class1 and class2.
program.h
struct thestructure
{
thestructure(class1, class2); //constructor.
[Code].....
View 5 Replies
View Related
Nov 24, 2013
In general, my problem is that I've been trying to reorganize the project I and my group are working on into separate project files. Everything was working perfectly fine before, but now I'm facing the wrath of undefined reference errors when I try to call my DLL functions.
I have them declared and included in the central header file here :
Code:
/* DLL functions */
typedef void ( * t_wait )( int milliseconds, const int frames_per_seconds );
typedef clock_t ( * ft_timer )( int command, t_timer * timer_object ); /* clock_t is usually defined as long */
typedef void ( * t_SDL_errorexit )( const char * message );
typedef SDL_Surface * ( * t_load_image )( char * image_path, unsigned is_transparent );
[Code]...
Then I have them imported here :
Code:
/* ******************************************************** */
/* ********* win_error( char *, bool ) ********* */
/* ******************************************************** */
/* - Displays a GUI for a windows specific error message, */
/* pass true to it to have it exit the program, pass false */
/* to have it continue */
/* ******************************************************** */
extern void win_error( char * message, bool is_exit )
{
/* Note : win_error uses the Win32 Api */
/* ********************************** */
char buffer[BUFSIZ] = { 0 }; /*
[code]...
This doesn't work, as my compiler sees it that I am trying to call invalid functions, whereas I have made sure to import the functions before calling. Obviously my compiler can't tell that, and is trying to protect me from calling them.
The source files are compiled as C++, but I'm using C-style code instead of true C++ code.
Obviously I'm using Windows style DLL linking, but if the only ways to share imported functions are non-standard, only post ways that will work on as low as Windows XP.
I have tried to statically link them before, but that led to a problem that I posted a while back. Which led me to dynamically linking, which was problem-free until I separated my code into separate files.
View 13 Replies
View Related
Mar 16, 2012
Here is what I did,
Code:
// A.h
const int salary = 1000000;
// B.h
extern const int salary = 1000000;
But I still got multi-definition errors. How should I fix it?
View 6 Replies
View Related
Dec 9, 2013
this last few days I've been coding this one particular file
Hero.cpp
namespace Hero {
namespace {
// all data here
}
}
then the code grew a bit to about 700 line
Then now I want to implement hero skill system It needs the access to data inside the unnamed namespace where I put just about everything.. but it's unnamed namespace, it's only valid within one file and I should hide all that data from Hero interface in Hero.h How should I do this ?
View 12 Replies
View Related
Jul 2, 2014
Basically i'm willing to create an application which could share Video,Mp3 Over the internet to my friends.
For suppose I'm hosting file on my PC, and i want to share "D" Drive to my friends but they aren't connected to my network locally. i want to share movies over the internet using a host and client application in c#.net.
the purpose of this application is very clear that that i want to share movies over the internet and they have to be able to watch movies on their PCs Except running my PC remotely.
View 8 Replies
View Related
Sep 16, 2013
When including a header file in stdafx.h, should that file still be included in the source file where it is actually used?
If it is included in both places, is the one in the source file ignored?
View 5 Replies
View Related
Feb 10, 2013
I have written my program and it works when I keep everything in the header files, and then have my main. I am now splitting them up into implementation files, but Eclipse keeps giving me errors. It gives me error at every opening brace of the constructor and functions. It says on all of them "Redefinition of (name of constructor or method), Previously declared here." What am I doing wrong, because it works in the header file?
#include "KeyValuePair.h"
template<typename Key,typename Value>
KeyValuePair<Key,Value>::KeyValuePair()
[Code] .....
View 3 Replies
View Related
Apr 12, 2014
I am working on an assignment in which i have to perform th following task
myClass itsObject1,itsObject2;
itsObject2=5000+itsObject1;
I have defined overloaded operator as follows in the header file but in the cpp file of the class it gives error.
friend vli &vli::operator + (int &a,vli &obj);
How to define it in cpp file of my class?
View 1 Replies
View Related
Sep 12, 2014
What is the right syntax for implementing the .cpp of a template class?
Consider this LinkedList.h file:
Code: #include<iostream>
#include"Iterator.h"
template <class T>
class LinkedList {
[Code] ....
How should the implementation for the LinkedList constructor, for example, should look like in the LinkedList.cpp file?
I tried this:
Code: #include "LinkedList.h"
template <class T>
LinkedList<T>::LinkedList<T>() {
// constructor
}
LinkedList<T>::~LinkedList<T>() {
// destructor
}
But the compiler wouldn't accept it.
View 4 Replies
View Related
Jan 17, 2015
lets say we have a valid class with full implementation, X. can this class be declared as forward in Y header file:
Code: class X;
class Y{
X* m_X;
}
but still be used as regular in the cpp file?
Code:
#include "Y.h"
#incldue "X.h"
T Y::function(){
m_X->doSomething();
}
visual studio prevents me from doing it , I wonder if the standard also says so.
View 2 Replies
View Related
May 21, 2014
I have been working a project in C++. I have TTTMain.cpp file that has all the function calls, TTTFuntions.cpp that has all the functions, I have TTT.h file that has all the prototypes and variables and additionally I have Winner.h that has enum class Winner declaration in it. Here is my block of codes:
Winner.h file:
#ifndef winner
#define winner
enum class Winner {
[Code]....
My question is when I compile this gives me error on
Winner gameSquares[] = { Empty, Empty,Empty, Empty, Empty, Empty, Empty, Empty, Empty };
with saying "invalid use of non-static data data member" and It says "Empty was not declared in this scope."
I know calling enum is very very trick.
View 3 Replies
View Related
Jul 29, 2013
I am beginner in c++ language. i'm use visual studio 2010 ultimate. the problem is i can't add c++ file(.cpp) and header file(.h).
Here the screenshot : [URL] ....
View 3 Replies
View Related
Dec 27, 2014
I made my header file. If cpp file with definitions is in project compiler knows it has to be linked, but if it's not compiler doesn't know. If I include standard library or boost I don't have to manually link cpps. How to do so including my header automatically links cpp? Maybe problem is with something else?I use VS 2013.
View 4 Replies
View Related
May 5, 2014
I was going through a code where i found the definition of int array[63] in one of the source files. But i also found the declaration as extern int array[66] in another source file. This is clearly wrong, but my doubt is how the compiler compiled it. It should have thrown error. In case if it compiles then what will be the behavior of the system? Will it be normal or some undefined behavior?
View 3 Replies
View Related
Sep 4, 2013
I use a programming language called layout which nobody here has probably ever heard of. It was discontinued over 15 years years ago but it was a very visual & easy to use piece of software - no coding required. In fact once you name all the variables on cards (forms) from then on it's just mouse clicking & occassionaly typing a number if required. It used blackboxes in a flowchart arrangement which were pre-done code for doing just about anything. i.e opening windows, handling numbers & text, files etc. I have written many programs with it including database management, quoting software & currently use it in my business to track my jobs & do invoicing & ordering. It's a pity it wasn't updated & still around today.
[URL]
Back to the problem. Being a 16 bit program it was written to run on Windows 3.1 but still works on Windows 7!! as long as it is the 32 bit version. I need to write a program that will run on 64 bit W7 without resorting to using a virtual PC solution. I have tried to find something similar that I might be able to use instead but so far nothing comes close to Layout. I just remembered today that layout can produce not only .exe programs but also various versions of C/C++ including visual c++. So I got this idea that if I could get those files I might be able to stick them into a C compiler program to re-make a "modern" exe file.
I could just do a simple sample program & send the source code to them to see if it works on a 64 bit version of Windows 7. how I can do this myself to produce a working exe file.
View 5 Replies
View Related
Jun 5, 2014
how to get source path of selected file.
for example :
selected image in E:/
E:ewfolderillustration.jpg
application - asp.net(C#)
View 4 Replies
View Related
Nov 3, 2013
Visual studio 2012
I have a project that has a few .asm files (assembly language code), I have the compiler/assembler set to create a list file for the assembly code and would like the debugger to use the .lst file for the source instead of the .asm files because in the .asm files the macros are not expanded like they are in the .lst files which makes debugging difficult sometimes.
View 1 Replies
View Related
Jun 14, 2014
I have four source files. The main source file includes two other source files. The two other source files both include the fourth source file. In the fourth source file I have an include guard. Will the code from the fourth source file exist in two locations in the compiled code? Is this something that is compiler dependent? An example of this is shown in the code below.
Code:
// filename: main.c
#include "source1.c"
#include "source2.c"
[Code]....
View 4 Replies
View Related
Mar 6, 2014
I have written a program that copies a file from the source and pastes it there (same location), but with a different name. The program works fine, except there is a small bug that i can't seem to fix. Here is the code:
/*
This program copies a file from the current directory and pastes it to the same directory, but with a different name. The file name form the source must include the extension as well.
*/
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
int main() {
char temp, s_file[100], d_file[100],
[Code] ....
This is the flow:
> 1) Enter the name of the file you'd like to copy (Must be from the current directory)
> A: 3.c // This depends if the file exists in the
> current directory
>
> 2) Enter the name of the destination file (The file will be copied to the same directory)
> A: 4 //The extension isn't necessary here
>
> Result: The file was copied successfully!
When I run the prg again, and this time input a file name with no extension, like this:
> Enter the name of the file you'd like to copy (Must be from the current directory)
> 3
> You did not enter a valid text. Press "?" to get help or "x" to exit.
I hit "?" and it takes me to
> 1. The file must be from the current directory)
> 2. The location mustn't be empty
Then it asks me
> Try again? (Y/N)
If i give N, it exits. BUT if I give Y, it goes, like this:
> Enter the name of the file you'd like to copy (Must be from the current directory)
> You did not enter a valid text. Press "?" to get help or "x" to exit.
You see, it doesn't give me the option to give it the file name..
View 3 Replies
View Related
Mar 16, 2013
I am using the OpenCV library (2.3.1-7) and Qt-Creator (2.4.1) and I have this simplified piece of code that reads in an image as cv::Mat and then applies the OpenCV function pyrDown to the cv::Mat.
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/gpu/gpu.hpp"
using namespace std;
using namespace cv;
int main()
[code]....
This piece of code runs just fine and puts out the two different images as exected.
What I need to do now is to retrieve the source code of the "pyrDown"-function and then modify it according to the needs of the project that I am working on.
If I comment out the following line
//#include "opencv2/gpu/gpu.hpp"
then this results in the following error message:
'pyrDown' was not declared in this scope.
Apparently, pyrDown only works if #include "opencv2/gpu/gpu.hpp" is included in my code. Therefore the header of pyrDown should be included in this file, correct?
I am using Qt-Creator and the tooltip text for "pyrDown" is as follows:
"void pyrDown(InputArray src, OutputArray dst, const Size &dstsize=Size())"
Therefore, when i checked the file "/usr/include/opencv2/gpu/gpu.hpp" (which is the complete path to the file), looking for the headers of "pyrDown" I expected to find a matching header.
But instead, I only found this:
//! smoothes the source image and downsamples it
CV_EXPORTS void pyrDown(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null());
struct CV_EXPORTS PyrDownBuf;
CV_EXPORTS void pyrDown(const GpuMat& src, GpuMat& dst, PyrDownBuf& buf, Stream& stream = Stream::Null());
[code]....
Those are all the lines of code where the character string "pyrDown" is included.To me, being rather a newbie, it is kind of strange that there is no header that matches the call of the function as it was included in my simplified code example at the very top of this post.
What I would like to understand is the following:
1) Is the file gpu.hpp really the one that stores the header that is used for the call in my code example? If so, I would like to understand why this is the case, since the data types of the parameters seem not to match (eg "GpuMat&" vs. "InputArray"). In gpu.hpp there are other files included, using the "#include"-command, but a text search in those files did not find any strings like "pyrDown" in any of them.
2) If gpu.hpp is not the header file that I am looking for, which one is the correct one and where can I find it?
3) The most important part for me is: Where can I retrieve the corresponding .cpp file for pyrDown, since this is crucial to the progress in my project. I have googled a lot and I found lots of .cpp files that were named "pyrDown.cpp" (example: [URL]), but none of them seems to be the one that I am looking for since either the data types in the header are not in accordance with what I expect or there are #include commands for files that I do not have available on my machine. And I assume that any .cpp-file that tries to use files that are not on my computer can not be the one that is used for the call in the code example at the top of this post.
View 3 Replies
View Related
Jan 5, 2014
All I am trying to do is create another source file in a simple Visual Studio C++ console application.
I get the following errors:
intellisense: expected a delcaration
error C2447: "{" missing function header
I didn't create another int main () in this source file, so what is causing these errors.
View 1 Replies
View Related
Apr 24, 2013
I'm about to begin work on an exercise that requires me to maintain a list of the variables inside a c source file. I'm trying to figure out how I'm going to pluck out the variable names from all the other noise. My first thought would be to count any word that isn't a keyword or other type of grammar syntax, such as parenthesis, brackets, semicolons, etc. right?
View 10 Replies
View Related
Apr 19, 2014
How to compile this source code and make a binary file
I think this need linux and run make command or gcc
This binary is a super user for android
source code attached
Attached File(s) : su.zip (7.59K)
View 3 Replies
View Related