C :: Passing Variable From Outside Function To Main?
Nov 8, 2013
This code is for a program that allows you to play a guessing game or arithmetic game and shows your total score from both as you go along. The program works fine the only problem I'm having is with the score. Is there a way to call the score value from the outside function into main?
Code:
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
//prototype functions
void menu();
[Code] .....
So trying to pass the value of score from the outer function int guessGame() into the score print statement in choice 3 of the main function? Oh and the "17 -turn_count" was just part of the requirements of the assignment.
View 6 Replies
ADVERTISEMENT
Mar 30, 2014
i would like to know if i need to dynamically allocate a string in main before passing it to a function that i have created.
in that function i just read the string and do not change any chat in it.
View 2 Replies
View Related
Nov 21, 2014
I have a a group of text files that are used as input into a program. Another very similar program needs the same data in a different input format. I am writing a program that will read in each line of data and parse it. I have successfully written the program in main() such that it will read until the end of file. However, I am trying to re-write the program such that the algorithm is in an external function and will read one line at a time and then pass all of the character strings to the main program. The program will not compile and I am positive it has to do with an incorrect use of arrays in passing the variable "token". I am attaching a copy of the main program and the function.
#include <iostream>
#include <fstream>
#include <cstring>
#include <stdio.h>
void Line_Parse(std::ifstream&,std::ostream&,const char* token);
int main(int argc, const char * argv[]) {
[Code] .....
View 2 Replies
View Related
Feb 3, 2015
I have the main() - which has entries like
Code:
main() {
int ss, ret, z;
float yy;
ret = function1(&yy, &ss, &z);
//int function1(flat *cc, int *dd, int *k) - is it correct?
[Code]...
View 5 Replies
View Related
Sep 14, 2013
I am getting a few compile errors for what might be a simple thing to do. I am opening a file in main, passing that pointer to a function and checking the contents of that file with a regex before I pass it on to build a BST. I am getting the following compile errors, what is wrong. Here are the errors:
Code:
gcc main.c fileCheck.c -o tree
main.c: In function `fileCheck':
main.c:19: error: syntax error before "FILE"
fileCheck.c: In function `fileCheck':
[Code] .....
Fatal error: Command failed for target `tree' Here is the two files and header that seem to be causing me the problems.
main.c
Code:
#include "main.h"
//#include "node.h"
int main(int argc, char *argv[])
FILE *fp;
if (argc > 2)
[Code] ....
And the header file.
main.h
Code:
#ifndef MAIN_H
#define MAIN_H
#ifdef __cplusplus
extern "C" {
#endif
[Code] .....
View 2 Replies
View Related
Jan 30, 2014
I'm currently writing a poker game and am trying my best to avoid using global variables. I have a few variables in int main() which i was hoping to use to store the value of each players hand. I then created a function which calculates the value of the hand but cannot get this value back into the main function.
For example:
Code:
#include <iostream>
using namespace std;
void getValue(int value) {
value = 4;
[Code] ....
Is there any way i can get the value of value using this function? If not what can I do?
View 8 Replies
View Related
Jun 4, 2013
Code:
#include <stdio.h>
#include <stdlib.h>
int size_b_row1;
int size_b_col1;
[Code].....
View 2 Replies
View Related
Jun 4, 2013
#include <stdio.h>
#include <stdlib.h>
int size_b_row1;
int size_b_col1;
int main(void) {
double C[4][4] = {{1,3,5,2},{7,6,2,2},{1,2,7,3},{2,3,5,3}};
double TC[4][4];
transpose(C, TC);
[Code] ......
View 2 Replies
View Related
Dec 24, 2013
I have a quick question about passing multiple variable to a func that has (stringstream & text). Here is the code:
void PrintText(stringstream & txt) {
cout << txt.str() << endl;
}
void main() {
[Code] ....
How to make second one work?
View 11 Replies
View Related
Feb 10, 2015
I have a 1wire program from maxim running in visual studio. There is this argument in the main function that requires the com port to be specified the command line. If I do pass it as "COM1" the program works as expected.
I don't want to depend on having to pass "COM1" in the command line and into main. I've tried creating a string for COM1 and passing it right into the if function but it doesn't work.
Code:
int main(int argc, char **argv) {
int len, addr, page, answer, i;
int done = FALSE;
SMALLINT bank = 1;
uchar data[552];
[Code] .....
View 1 Replies
View Related
Dec 7, 2014
I'm trying to pass the value of an object created from a class file to a function outside of the "Int Main" function in the main.cpp file. I've successfully created the object, I just want to pass it to a void function but I'm getting the scope error below. I'm not sure how to correct. I'm not having much luck with research either (static variables?).
error: 'TicTacToe' was not declared in this scope
main.cpp
#include <iostream>
#include <cstdlib>
#include "Signature.h"
#include "Gameplay.h"
using namespace std;
// Initialize array
char square[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
[code]....
View 4 Replies
View Related
Sep 7, 2013
The problem that I want to make an array " vertextDegree [nbColours] " with " nbColours " elements in it ,but the "nbColours" unknown and I have to get it get it from a file .
Code:
int nbEdges,nbVetices, nbColours ;
typedef struct st_graphVertex {
int index;
int colour;
int val ;
int vertexDegree[nbColours]; // it won't work because nbColours unknown
// here and I want get it from file in the main
struct st_graphVertex *next;
t_edgeList *out;
}t_grapheVertex;
View 3 Replies
View Related
Nov 14, 2013
When a declare a string e.g.
Code:
char str[30]; as a global variable, the srting is initialized to NULL.
But if I declare char str1[30] INSIDE main(), then the string has garbage inside.... Why this happens??
E.g. the following code snippet...
Code:
#include <stdio.h>
char str[50];
int main(){
char str1[50];
[Code] ....
View 4 Replies
View Related
Apr 6, 2012
I want to know
prog1.c
#include<stdio.c>
static int c=6;
int main() {
/*code*/
}
prog2.c
#include<stdio.h>
int main(){
static int c=10;
}
what would be the difference between these two program in the fuctioning of static keyword ?
View 1 Replies
View Related
Jan 19, 2013
Ok so I am working on a game and I'm in the process of developing my Player class. Anyways, what I have is a keyboard function that is called in my main function to make a shape move.
void myKeyboardFunction(unsigned char key, int x, int y) {
switch ( key ) {
[Code].....
But when I try to call it, trying to copy my previous method,
glutKeyboardFunc(Player1.playerControls);
I get an error
error C3867: 'Player::playerControls': function call missing argument list; use '&Player::playerControls' to create a pointer to member
I get an error saying it can't convert parameters. I would just like to understand why the arguments become a problem when I make the function a member of my class, when the first method I used is so easy.
View 2 Replies
View Related
Sep 8, 2014
#include<iostream>
using namespace std;
int main(){
int size_col = 12;
int size_row = 12;
char months_array[12][12] =
[Code] ....
I am having problems with passing a block of a char to a variable, so i could print it out.
It gives me an error: value of type *char cannot be assigned to a entity type char.
View 7 Replies
View Related
Jun 9, 2013
The function is supposed to return value from the file in my main, but I am getting empty value. I am trying to get better with pointer. Right now just teaching myself.
right now the only way for this code to show value is when in put the putchar(*ps) inside my readfile function. I would like to readfile to return value and print in the main function.
Code:
#include <stdio.h>
char *readfile(char filename[]);
int main(int argc, char *argv[] ) {
[Code].....
View 4 Replies
View Related
Mar 30, 2014
I have program where i have to check to see if file exist, if it does not then it needs to be created. SO I have a read file that works fine, if th efile exist it reads whats in it, if it does it says the file does not exist. Now Im trying to creata function that creates the file if it doesnt exist. so in my read function when the person enters the name of the file to be checked for..I pass that name to a variable called name..Hoping that I could then pass it into my create file function if it does not exist..and use that variable to pass the name they entered into the createfile array..called filename.. but I am having trouble because i get error when i try to pass from a string name to char array.. even when I change the varialbe name to char, or char [256] it will not work.. I try to fing a way to convert th string to a char using the strncopy function but still no dice..here the code i have for the createfile funciton
void CreateNew(ofstream & FileNew)//Create file
{
char filename[256];
string name;
[Code].....
How can i do this without having to ask the person to enter the file name twice..
View 12 Replies
View Related
Mar 25, 2013
I have create a function which able to return value for variant of variable through a LPVOID parameter function.
Here is my coding.
Code:
void main()
{
CClassA a;
BOOL bAssign=FALSE;
CString str;
[Code].....
View 6 Replies
View Related
Dec 12, 2012
I am attaching a sample project. Basically what this project does is that I initialize a variable map<CString, bool*> m_mapTest in CView::OnInitialUpdate and then pass the variable to CDocument class. On the other hand, within the function OnSaveDocument defined in CDocument I check m_mapTest. To my surprise, the CString part of m_mapTest is correct but the bool* part of m_mapTest is wrong(I pass an array of bool in CView::OnInitialUpdate).
View 3 Replies
View Related
Aug 31, 2014
So I have a class object that contains the private member variable spot and the public member function MoveLock. Within MoveLock, is a member variable called numbers that holds the place where a user is on a "lock knob". Now, what I'm trying to accomplish is that whenever the user turns the "knob" in the wrong direction, the position is updated with that current numbers so that the clicks needed to unlock the first state is also updated. But I get these errors:
Error E2096 C:Users...switchtest.cpp 34: Illegal structure operation in function main()
Error E2294 C:Users...switchtest.cpp 39: Structure required on left side of . or .* in function main()
Ultimately, what I have in main() is a piece of what I'm going to implement in a class member function. I'm also thinking about moving the if else statements out of the for and creating a second one for the else portion.
#include <iostream>
#include <windows.h>
#include <iomanip>
using namespace std;
HANDLE inKeys = GetStdHandle(STD_INPUT_HANDLE);
HANDLE screen = GetStdHandle(STD_OUTPUT_HANDLE);
[code]....
View 10 Replies
View Related
Dec 26, 2014
I am writing a program in which a Fucntion has to be wriiten to parse the Command Line . When I include Code for parsing in main fuction iteslf ,its run ok . But I want to make a fucntion of that code and call it from main ,than it show Segmentation error .
By using Debugging I found Some thing is mess with " -m" Parameter of Command line , But Cant Rectify it ..
Code:
int main (int argc, char *argv[]){
//get_parameter_value(argc,argv);
// buffer[packet_size+1]= char ("'");
while (argc > 1) {
if (argv[h][0] == '-')
[Code] .....
View 3 Replies
View Related
Feb 13, 2014
int example (int [], int, *int,*int,*int,*int);
int main () {
My code will be here
example (int array[], int size, &a,&b,&c,&d); // Like this??? I try it didnt work
[Code] ....
View 2 Replies
View Related
Aug 27, 2013
I am trying to run a programme implementing a function with structures in c... which is:
#include<stdio.h>
#include<conio.h>
struct store {
char name[20];
float price;
int quantity;
[Code] .....
View 1 Replies
View Related
Apr 24, 2014
Why the value does not return; Here is code
#include <iostream>
#include <string>
#include <ctime> // to use the time function
#include <cstdlib>
using namespace std;
int getUserChoose (int);
[Code] ....
here is the output
Welcome to the program of Rock, Paper, Scissors
The computer is ready to play the game
Are you ready to play the game
Y for yes and N for no
Y
R = Rock; P = Paper; S = Scissors
R
You have choose Rock
1TN
1RM
0U
0C
View 5 Replies
View Related
Jan 24, 2013
If so what is the reason, and the returning int value indicates wat?
View 4 Replies
View Related