C :: Pass Values In Functions And Writing Them To A Txt File
Aug 23, 2013
This code is for fun, and have it doing a lot of what I want it to, just not all. I want random generated to write to a txt file. I tried to use an array but that failed. I wanted to use an array because i am only passing one value. Which makes sense since the random generated function is an int.
I made the fprintf as a comment but hopefully soon it will be able to send the values to the txt file. After that I will tackle the function.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define HIGH 49
#define LOW 1
int random_generated()
[Code]...
View 11 Replies
ADVERTISEMENT
Dec 29, 2012
Code:
struct NewPlayer {
int level;
int intelligence;
int damage;
};
int CharacterInfo(NewPlayer MageWizard, int Clevel,int Cint, int Cdam)
[Code] .....
View 1 Replies
View Related
Sep 23, 2014
I have read about it in my book and also on this website but i still have things uncleared....
View 11 Replies
View Related
Jun 29, 2014
I'm playing around with GTK+ 2.x and currently I have a button to call a function like so:
Code:
void selectmod(GtkWidget *downloadbutton, GtkComboBox *modlist, gchar *data){
gchar *mod = gtk_combo_box_get_active_text(modlist);
printf("
%s", mod);
}
How can I pass the *mod variable to another function?
View 9 Replies
View Related
May 25, 2013
I get a run time error saying something about memory locations when I run this program.How can I make this program work using pointers?
//this program converst miles to km
#include<iostream>
#include "std_lib_facilities.h"
[Code]....
View 1 Replies
View Related
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
Feb 25, 2014
I need to send same instance of object of a class in two function (Main function and thread function). The class is something like this:
//The class need to have constructor.
Class ABC {
public:
DWORD *IdG;
ABC(int number) {
IdG = new DWORD[number];
}
}obj(32);
The obj(32) is called in following two function. Function F1 is called using thread in main function.
void F1() {
obj.test;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) {
obj.test1;
_beginthread(F1,0,(void*)number);
}
The code works well when the object of class ABC is created as shown above. My problem is the value that is passed in the object ('32') is to be read from the file.
If I read the file and create object separately in Main function and function 'F1' then , function 'F1' is not executed.
How to create same instance of object for Main function and function 'F1' with value passed in the object taken from the file.
View 1 Replies
View Related
Jul 13, 2014
I have a project for class where I have to create a structure and get user input for 3 structure variable arrays of 10. I am trying to figure out how I can use the same function to fill my different section of variables.
My Structure is an employee file of ID number, name, hours, payrate, and then gross pay. I have to create a function for each input function. I am confused on how to pass the structure variable so that I do not have to write 3 functions for each input. I would like to be able to get all the info for the first structure variable and then recall the same 5 functions for the next before moving along. I hope that I have been able to make this clear. Here is my code:
#include<iostream>
#include<iomanip>
#include<cctype>
#include<string>
#include<cstring>
using namespace std;
struct PayPeeps_CL//Payroll Structure {
[Code] .....
View 14 Replies
View Related
Jul 6, 2013
I am trying to get this statistical equation to work. m! / n! (m-n)!.
Code:
#include <stdio.h>
long factorial_M(long); // function prototype //
long factorial_N(long);
long total (long);
int main(int argc, const char * argv[]) {
[Code] .....
View 13 Replies
View Related
Jan 24, 2013
Why do we not pass the address of the string during printf or scanf functions like we do for Integer or float variable types?
View 2 Replies
View Related
Oct 1, 2014
I am returning area from areaCircle(), but do not know how to print it in main. I know this program has lots of errors, two cases that I have listed.
Not sure how to properly list multiple function calls in a switch statement, and how to print one's return from main.
int main() {
char choice;
double area;
showMenu(choice);
switch (choice) // If input is C, use getRadius, areaCircle and count, then print the are
{
case 'C': void getRadius(),double areaCircle(), void count(bool display = false);
[Code]...
View 5 Replies
View Related
Nov 7, 2014
I built a program that finds the average amount of days missed per employee. I am now attempting to modify my program to pass values by reference rather than passing by value. I created 3 functions: int numOfEmployees(); int numOfDays(int); double avgDays(int, int);
in the prototype I use the ampersand sign int numOfDays(int&);
in the actual function I use numOfDays(int& employees)
I am just not able to get the call to the function to work the program will crash when I modify it with the ampersand signs.This is the original code I am trying to modify:
#include <iostream>
using namespace std;
int numOfEmployees(); //Prototype for numOfEmployees
int numOfDays(int); //Prototype for numOfDays
double avgDays(int, int); //Prototype for avgDays
[code]....
View 1 Replies
View Related
Nov 7, 2014
I built a program that finds the average amount of days missed per employee. I am now attempting to modify my program to pass values by reference rather than passing by value. I created 3 functions:
int numOfEmployees(); int numOfDays(int); double avgDays(int, int);
in the prototype I use the ampersand sign int numOfDays(int&);
in the actual function I use numOfDays(int& employees)
I am just not able to get the call to the function to work the program will crash when I modify it with the ampersand signs. I know I have to re-work my program, but I am having a hard time understanding how.
This is the original code I am trying to modify:
#include <iostream>
using namespace std;
int numOfEmployees(); //Prototype for numOfEmployees
int numOfDays(int); //Prototype for numOfDays
double avgDays(int, int); //Prototype for avgDays
[Code]......
View 1 Replies
View Related
Jan 15, 2015
Well I know how to pass values between forms using get and set properties. But the problem with it is everytime I want to pass values from form2 to form1 it doesn't appear. To make it appear I have to type form1.Show(); which open form1 a second time and then show the value. Is there any way I could make it appear without using form1.Show();?
View 9 Replies
View Related
Mar 4, 2015
I need to pass multiple values from one function to another and how to do this. Here is my code so far.
#include <iostream>
#include <string>
#include <cctype>
#include <fstream>
using namespace std;
//Function Prototypes//
int charString(string, string, string);
string reverseString(string, string, string);
[Code]...
I basically need to take line1, line2, and line3 and return them to the reverseString function. Also, I am not allowed to do anything like make my own classes. I have to stick to the basics and no higher level programming techniques since we have not learned them yet.
View 5 Replies
View Related
Jul 19, 2014
I am using a struct and tying to send values to it as byte value
Code:
#include<stdio.h>
typedef struct{
unsigned r1:1;
unsigned r2:1;
unsigned r3:1;
[Code] ....
Error: invalid suffix "b00100000" or incompatible types in assignment
I am able to access the member as Range.r1 = 1; and have no problems. I want to send data whole at once, but how ?
View 8 Replies
View Related
Aug 5, 2013
I am trying to write down in binary format an array of unsigned int values but i get the following compilation error :
: In function ‘int CIndex(std::fstream&, std::fstream&, std::fstream&, std::fstream&)’:
./src/IndexBuilder/index.cpp:23:26: error: no matching function for call to ‘std::basic_fstream<char>::write(int*, long unsigned int)’
./src/IndexBuilder/index.cpp:23:26: note: candidate is:
/usr/include/c++/4.6/bits/ostream.tcc:184:5: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::write(const _CharT*, std::streamsize) [with _CharT = char, _Traits = std::char_traits<char>, std::streamsize = long int]
This is the part the is not working:
Code:
// uia is : unsigned int * uia;
// then I have allocated the space for it
// load it with unsigned int's
// k is the number of variables in my array
o.write(uia,sizeof(unsigned int)*k); But thsi should be so simple and strait forward.... in c i do it as :
Code:
fwrite(uia, sizeof(unsigned int), k , fp); but since i would need to convert fstream to FILE* i decided to do it c++ way.
and this is how i opened the file :
Code:
o.open (fileName.c_str(),std::ios::out|std::ios::binary);
View 5 Replies
View Related
Jul 31, 2013
I just got a job programming a windows application. One of the requirements is reading and writing values from an excel spreadsheet. Looking online, it appears that C++ isn't the best (one of the worst?) languages for reading and writing values from excel files. Now the language I'm most familiar with is C++ and I've been looking at C#, and it appears to be much easier to read excel files.
View 8 Replies
View Related
Jun 4, 2012
I am really desperate on trying to make my code work. The code is to find the eigen values of any given matrix of dimension NxN. The input can be the diagonal of any NxN matrix alongwith its subdiagonal. The code works fine for N~350 or so but when i go beyond that these errors appear.
First-chance exception at 0x00425ea4 in divide.exe: 0xC0000005: Access violation writing location 0x01141000.
Unhandled exception at 0x00425ea4 in divide.exe: 0xC0000005: Access violation writing location 0x01141000.
But as i have never declared any variable statically and when i dynamically allocating memory with variables it should work like it does for smaller N values.
View 14 Replies
View Related
Nov 27, 2014
Write a function named cointoss that simulates the tossing of a coin.
When you call the function, it should generate a random number in the range of 1 through 2.
If the random number is 1, the function should display "heads".
If the random number is 2, the function should display "tails".
Demonstrate the function in a program that asks the user how many times the coin should be tossed, and then simulates tossing the coin that number of times.
Report the total number of heads and tails.
View 2 Replies
View Related
Jul 29, 2013
I am trying to get some confirmation about how to pass to functions. If you want to assign default values to certain parameters, and have others defined inside the body of int main(), then the parameters which will have default values go at the end of the list. Is that correct?
i.e. The following code is wrong, because we cannot leave a black in the function call on the third line of the main function. However, if we switch the prototype to void Passing (int a, int c, int b = 1); and the function definition to void Passing (int a , int c, int b) everything will be okay and we can call the function as Passing (a, c).
In brief, we cannot do this EVER:
Passing( a, , c)right?
#include <iostream>
using namespace std;
[Code]......
View 4 Replies
View Related
Apr 9, 2014
I have an assignment in my C++ class that is to create a menu based coffee shop program. Here is what I have so far:
#include<iostream>
#include<cmath> //doubt this is needed but i added it just in case
using namespace std;
[Code]....
View 19 Replies
View Related
Nov 5, 2014
I was given an assignment where I have to input two points (four integers) on a Cartesian plane from a file and then process it using functions. My professor is very particular so the comments are a bit excessive, but here's what I have.
double radiusFn(double, double, double, double);//4 double values, one for each point. All points are needed for the calculation of distance in this function.
double diameterFn(double);//Only uses one double value - the radius. Both functions below use the same value.
double circumferenceFn(double);
double areaFn(double);
int main() {
[code].....
The file reads:
Quote
1 2 3 4 5 6 7 8 9 10 11 12
View 2 Replies
View Related
Mar 22, 2013
Code:
#ifndef CANDIES_H
#define CANDIES_H
#include <iostream>
#include <fstream>
#include <Global.h>
class Candies
[Code]...
Code:
#include "Candies.h"
#include <Windows.h>
#include <iostream>
#include <fstream>
#include <sstream>
[Code]...
When I tested it, the file name in getName() outputted the right file name. However the file name in loadName() does not print out anything in the console window.
I want it to be so that the strings in [I]name_addTXT.c_str() in both functions are equal.
View 4 Replies
View Related
Sep 5, 2014
What "int values" is supposed to mean as parameters to these functions? I'm not sure what do with them. Also how to input values into the array via functions. I was trying to but I just don't understand how to connect a user's input to a function to then enter into an array.
// input reads “values” integers from the user to place in the array data. It prompts the user for each value individually with the ordinal position of the value.
void input (int data [size], int values);
// Places the sum of corresponding values from arrays a and b and places the results in array s. The first “values” integers in the array are processed.
void do_sums (int a [size], int b [size], int s [size], int values);
[Code]...
View 2 Replies
View Related
Aug 13, 2014
I am trying to understand RValue-references as return values of functions. First let's consider a simple function, that transforms a string into upper case letters.
const std::string
toUpper(std::string orig) {
std::transform(orig.begin(), orig.end(), orig.begin(), ::toupper);
return orig;
[Code] .....
It compiles, but I get the output 0 . Here I am wondering why the code above does not move the substr correctly while the code below does (prints out 1):
const std::string&&
no_sense(std::string abc) {
abc = abc.substr(1, 1);
return std::move(abc);
[Code] .....
In both cases abc is a temporary object inside of the function and gets deleted after the function is left. But why does the second version work and the first one does not?
cat.substr(1, 1)
And as my last question. Why doesn't
return std::move(abc.substr(1, 1));
work?
View 3 Replies
View Related