C :: Functions That Declare Arrays In Function Input Even Though Already Declared In Main

Mar 6, 2015

I have seen functions that declare arrays in the function input even thou the arrays is already declared in main. Why do you do this?

For example:

int ova(int antal, char glosorSv[][MAX], char glosorEn[][MAX])
int main(void)

char glosorSv[][MAX]
char glosorEn[][MAX]

View 2 Replies


ADVERTISEMENT

C/C++ :: Main Function Can Only Declare Variables And Functions

Mar 9, 2015

I need making my main function to run while not having any if or for statements. It can only declare variables and functions. Since my main function has command line arguments, how to so.

// This program counts all the words in a given file.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char* argv[]) {
FILE* txtFile = NULL; // File Pointer
char str[1000000];

[Code] ....

View 5 Replies View Related

C :: How To Make Main Function Only Allowed To Declare Variables And Functions

Mar 6, 2015

So I need to make a main function have no if/for/etc. statements so I need to move it to another function and call it in main. The problem is that it's a command line argument function so I'm confused on how it works. Here's an example:

Code:

#include <stdio.h>
int main(int argc, char* argv[])
{
printf("The program name %s", argv[0]);
if (argc == 2) {
printf("Argument supplied is %s", argv[1]); }
else if (argc > 2) {
printf("Too many arguments");}
else {
printf("One argument");}
}

How can i make this into two functions with main only declaring variables and calling other functions?

View 2 Replies View Related

C++ :: Globally Declared Arrays Accessed By Multiple Functions

Mar 15, 2013

I currently have globally declared arrays, which are accessed by multiple functions. I want to turn the program so that the arrays are no longer globally declared, but are passed to functions by reference.

I have one problem with passing the arrays: I found that, through debugging, I HAVE TO resize the array when I pass it by reference. For instance, I was using int a[10] when it was globally declared, when it is passed by reference with size 10, it does not work, instead it should be higher than 10 (certain number). Why is this happening? I do not get it...

View 6 Replies View Related

C++ :: Program To Display Other Functions In Int Main Function

Oct 13, 2013

I would like my program to display other functions in the int main function. For example, this is what my program looks like:

int Function1(int &var1, int &var2, int &var3) {
cout << "blah blah blah" ;
cin >> var1 ;
var2 = var1 * 3 ; //example
var3 = var1 * var2 ; //example
if(blah blah blah)

[Code]...

View 2 Replies View Related

C :: Use Main Function To Ask For Input To Convert Hexadecimal To Binary

Mar 15, 2013

Code:

#include<stdio.h>#define MAX 1000
int main(){
char binaryNumber[MAX],hexaDecimal[MAX];
long int i=0;
printf("Enter any hexadecimal number: ");
scanf("%s",hexaDecimal);

[Code]...

So this is my current code, is there anyway I can reduce the size and use a main function to ask for input and a call function to do all the conversion and return it? I am confused for the past few days trying to figure it out and finally ended up here. Anyway can I write it as a something like this

Code:

int main()
{
//ask for user input hexadecimal into here and call a let's say hex2binary() function
}

int hex2binary(...)
{
//an array with dynamic memory, malloc? and convert it and return values
}

I don't really need the full code, just a simple instruction on how and where to start.

View 2 Replies View Related

C++ :: How To Declare Functions

Aug 19, 2013

How to declare functions in C++

View 1 Replies View Related

C :: Declare Global Array And Then Use It In Few Functions

Jan 22, 2015

I want to declare a global array and then use it in a few functions. When I want to assign any number to that array I face with this error:

Code:
a.c:11:6: error: expected expression before ']' token
n[]={1,2,3,4,5};
^

The code is:
#include <stdio.h>
int n[5]; // I need to define the array here to be global
int main () {
n[]={1,2,3,4,5};

[Code] .....

View 6 Replies View Related

C :: How To Declare A Group Of Arrays Of Different Sizes

Oct 15, 2013

I'm building a box to take in several arrays of different lengths. one group happens every 10 seconds. one of them happens every 5 seconds. this is from a weather station.

10 sec
subgroupA[14]
subgroupB[24]
subgroupC[17]
subgroupD[12]
subgroupE[34]

5 sec
subgroupC[17]

I plan to retransmit them, substantially unchanged at a lesser rate to save radio power over a serial data link. buried in groupD, I want to change a few chars before retransmit.

I don't want to go to the trouble of doing a structure for each of them since most will be resent unchanged. some entries are chars, some are decimal, some are a mix. I guess it might be convenient to further define groupD, maybe not.

what is the best way to declare the group? I want them to be contiguous since that's how they will end up in the tx buffer. Each subgroup has its own checksum, so I planned it this way to make checksum more convenient.

View 6 Replies View Related

C++ :: Implement Member Functions Of Class Function - Failing To Get Input

Aug 17, 2013

I am supposed to implement the member functions of class Person.

class Person {
public:
Person();
Person(string pname, int page);
void get_name() const;
void get_age() const;

[Code] ....

The code I wrote is below. Where I am struggling is the program does not allow me to input age. Therefore, I cannot test if my temp for age works. It automatically defaults to 0 because it hasn't taken input. Here is my code:

// Program Title: Person function
// Program Description: The program prompts the user for first and last name and age.
// It then prints the output that was provided by the user.

#include<iostream>
#include<string>
using namespace std;
class Person {

[Code] .....

View 13 Replies View Related

C :: Declare Two 1-dimensional Parallel Arrays Of Integers That Will Hold The Information Of Up To 10 People

Jul 30, 2014

In pseudocode and in C code, declare two 1-dimensional parallel arrays of Integers to store the age and weight of a group of people that will hold the information of up to 10 people. Use a For loop to iterate through the array and input the values. This is the code i have, but my array is showing up as 11 and not 10?

Code:
#include <stdio.h>
int main() {
//Define Variables
float Age_Data[10],Weight_Data[10];
float Age_Input,Weight_Input;

[Code] .....

View 3 Replies View Related

C :: Difference Between Two Int Main Functions

Feb 6, 2014

I just wanted to know what's the difference between these two types of main functions:

Code: int main (int argc, char** argv){ ... }

Code: int main (int argc, char* argv[]){ ... }

View 4 Replies View Related

C++ :: How To Pass Arguments From Other Functions To Main

Sep 6, 2013

How to pass arguments from other functions to main. i want to write a program like nano well not exactly like nano editor. I have a function f_read(char* filename[]), and fopen() get filename[1] as file name and *filename[2] as "r" read mode and rest of the code will read from a file.

I want is this char filename[] to main(int argc , char argv[])

how can i do that??

View 4 Replies View Related

C :: Write A Program With Two Functions Both Called From Main

Mar 14, 2013

Write a program with two functions both called from main(). The first function just prints "Hello". In the second function ask the user to enter a number. Calculate the square root of the number and return the result to main(). In main() print the square root value.

Code:

#include<stdio.h>
#include<math.h>
float fun3 (float );
main()
}

[code]...

View 3 Replies View Related

C++ :: How To Implement Main Queue Functions Using Two Stacks

Nov 8, 2014

How to implement the main queue functions Enque() and Deque() using two stacks S1 & S2. You allowed only to call push () and pop() functions of the two stacks to implement Enque()and Deque() functions.

#include<iostream>
using namespace std;
const int size=5;
int arr[size];
int front=-1,rear=-1;
bool isfull() {
if(rear==size-1)

[Code] .....

View 4 Replies View Related

C/C++ :: Accessing Functions And Objects Within Class From Main

Apr 28, 2015

We are coding a Blackjack/21 game. I have a Deck.cpp class, Deck.h, Play.cpp (holds Main), and Card.h (holds card struct). I also have a Hand class/header, but I'm not using it yet. This is what is required per instructor.I am having issues accessing the functions that are in my Deck class. I have tried a few other means to access the class's function, but I've already gotten rid of those. These three are my latest attempts with the specific errors in the comment on the line the error was happening.
ve.

Here is my Deck.h

#pragma once
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include "Card.h"
#include "Hand.h"
using namespace std;
class Deck

[Code]...

View 3 Replies View Related

C/C++ :: Passing Var Assigned In A Class File To Functions Outside Of Int Main?

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

C++ :: Validating User Input - How To Declare Array Of Character

Apr 29, 2012

Question simple like that: Let user enter some words from keyboard, one word per line until a '.' (period) entered then print out result, for example:

Code:
Enter a word: word1
Enter a word: word2
Enter a word: .
You have entered 2 word(s):
word1
word2

Problem is I don't know how to declare the array of character at the beginning since I don't know neither how many word user may enter nor how many letter of each word. So I go ahead and declared like this: char word[20][50] but I know it is not best way.

Code:

int main () {
char word[20][50]; //array has maximum 20 words, each word maximum 50 character
int i=0, number_of_word;
do {
printf ("Enter a word: ");

[Code] ....

View 3 Replies View Related

C :: Save Data To Arrays Defined In Main Using Their Addresses

Dec 30, 2013

so i have two classes ( main and another one ask ) in main i have defined 3 arrays (char drivers[250] ,offences[250] , owners[250]) and also included their pointers ( char *drivers_ptr,*offences_ptr,8owners_ptr)my problem is that i need to set values (actually 1 string of 250 chars to each of these arrays BUT from the class ask without making these arrays global -as this is prohibited by my university exercise !- )

so my question is how will i manage to save data to the arrays that i have defined in main using their addresses(through the pointers of each one that i have passed to the ask class) from the ask class ?

View 4 Replies View Related

C++ :: Declared By Function

Aug 20, 2013

MCLoad.h - MCLoad.cpp
bool MCLoad::Load(SDL_Surface* Name, std::string File){
Name = NULL;
Name = SDL_LoadBMP(File.c_str());
if(Name == NULL){return false;}
else{return true;

[code].....

compiler gives me the error bg was not declared in this scope. i googled it.

in MCInit #include <SDL/SDL.h> #include "MCLoad.h"
in MCLoad #include <SDL/SDL.h> #include <string>
in MCClean #include <SDL/SDL.h> #include "MC.h"

View 14 Replies View Related

C++ :: Why Does GetY Have To Be Declared After Struct Y Is Declared

Jan 30, 2013

struct x
{
y *GetY(); //error: what is "y"?
struct y
{
};
};

Why does GetY have to be declared after struct y is declared? I thought order of class members in C++ did not matter? Does it have to do with the way parsing is done?

EDIT: It also doesn't work if I typename x::y *GetY();, which makes even less sense to me.

EDIT: It works if I forward declare, but this goes against everything I know about C++ classes...

View 6 Replies View Related

C++ :: When To Declare A Member Function As (const)

Sep 27, 2014

i am trying to describe the unusual situation where you declare a class member function with this format:

bool class::function_name(void) const

Specifically where the 'const' follows the parameter list. It is my understanding this is a very useful way of ensuring that whatever code you put in the function definition cannot change any data members of its class.

However I have recently read that this form of declaration should not be used as it leads to less optimized and slower code. Is this correct?

View 3 Replies View Related

C/C++ :: How To Declare A Function For Summary Report

Oct 12, 2014

#include <iostream>
#include <cmath>
using namespace std;
void summary();
const float below100 = 0.10;
const float after100 = 0.05;

[Code] .....

It cannot loop back to the top coding, cause what i want is the code can loop back to the 1st cout question, and it will asking over and over again, and how to declare a function for the summary report?

View 2 Replies View Related

C++ :: How To Pass Constant BYTE Array Declared In Function As Parameter

Apr 20, 2013

I have this code:

const BYTE original[2][4] = {
{0x00, 0x00, 0x00, 0x00},
{0xFF, 0xFF, 0xFF, 0xFF}
};
void function(const BYTE** values){

[Code] ....

You might notice that the above code doesn't compile, this is the error:

cannot convert parameter 2 from 'BYTE [2][4]' to 'BYTE *'
1>
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

Even after some search I couldn't really find an answer to my problem, how do I pass the const BYTE array which I declared above in the function as a parameter (or what structure do I need to set for the function as a parameter)?

View 10 Replies View Related

C :: Declare A Struct Then Pass It As A Parameter Into Function

Dec 8, 2014

I have some code here where I try to declare a struct then pass it as a parameter into a function to do something to it:

Code:
struct _user {
char * initial[3];
int pos;
} user;
int initial_add (struct user * initial_list, int initials, char * buffer) {

[Code] ...

I get the error :
server2.c:15: warning: "struct user" declared inside parameter list
server2.c:15: warning: its scope is only this definition or declaration, which is probably not what you want

[Code] ....

View 6 Replies View Related

C++ :: Keyboard Function That Is Called In Main Function To Make Shape Move

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







Copyrights 2005-15 www.BigResource.com, All rights reserved