I have a function that returns a char*. No problem. But I need to concatenate another array with the results of this function. I'm getting a segmentation error.
Code:
//this next line outputs correctly so I know my function is working
fprintf(stdout, "%s
", get_filename(selection));
char* temp;
I've made a code to check whether or not a save file has been created correctly, but for some reason it always returns this line: readdata[qa]=='1' as true. in which qa is the counter I use in a for loop and readdata is a character array consisting of 50 characters that are either 0, 1 or 2.
this is the entire code:
#include <iostream> #include <fstream> #include <string> using namespace std;
[Code]....
at first is also went wrong at line 22 and also returned that as true, but then I added brackets and it worked.
I do not understand how I can implement this.If fread != to at least 8 bytes then do THIS: printf (" your file is near the end of file", fread result);
For a Homework i need to make some kind of Minesweeper but i have one Probleme one of my functions always return teh same and i cannot fin out why here is the code:
bool setzen(int x, int y){ if(feld[x][y]!=3){ return mine=false; }
[Code]....
Thats the Part where Everything happens but the Function "bool setzen" always returns false and i dont know why.
Is it possible to create a function that can both return and display a value. I was trying to make a program that computes and prints terms of the Fibonacci series using a recursive function.
I am writing a program with a function that includes a long loop. I need this function to return a value when each loop is done, to send this value to output, in order to follow the progression. But I don't know how to do it in easy way. The function is like follow:
int goC(){ ... // some local value definition for(int i = 0; i < 1000; i++){ ... // a lot of calculations done here return i; // -> return the value after each loop is done } }
Here it only returns one value, i = 0. Clearly it's wrong.
I'm writing a function that is to return the price of something.. What would be the most appropriate return type for this? Like in Java it would be a double...
How to go about making a function that accepts an integer and returns a string with any one of 5 strings containing the name of the object. For example object number 3 might be "Pen". Object 4 might be "Paper".
I need to create a function that takes as an input a variable number of scalars and returns the biggest one. Just like std::max() does for 2 elements, but I need it for an undefined number of elements, can be 2, or 5, or 10 etc.. How to approach this?
What I need it for: I'm working with a bunch of vectors, maps, etc. and I need to find out which has the most elements. So I was thinking that I should end up with something like
int biggest = max(vector1.size(), vector2.size(), map1.size(), ...);
I have a big problem with a function, I wrote this function in order to get a line from an HTML (Or XML) file, until a specified delimiter (not always or ... It can be everything..)
Here is my code :
public static String GetLineUntilChar( String url , char delimiter , String postData, String referer, String cookie ) { try { Uri uri = new Uri("http://127.0.0.1//site.html"); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); request.ContentType = "application/x-www-form-urlencoded"; if (!String.IsNullOrEmpty(referer)) request.Referer = referer;
I have a matrix that contains zero and nonzero elements. I want to do a function that return 3 arrays.
The first one is for nonzero elements the second array contains the corresponding row numbers of each nonzero element the third array contains the corresponding column numbers of each nonzero element.
Write a function that computes and returns the score for a permutation, i.e. the number of reversals required to make arr[0] == 1. HAVE TO USE FOLLOWING FORMAT:
Code: // POST: Returns the number of reversals needed to make arr[0] == 1 // if the reversal game were played on arr // Note: If arr[0] == 1 initially, then score(arr, n) returns 0 AND this is what i could muster; [code]....
I have an assignment which requires me to do the following:
Required to write a function that finds an integer in an array and returns its corresponding index. The function must be called findNumber. It must have FOUR parameters:
- The first parameter is the array to be searched - The second parameter is the integer to be found within the array - The third parameter is the size of the array - The fourth parameter is an integer that indicates whether the array is sorted. A value of 1 means the array is sorted; a value of zero means the array is not sorted.
Since a function can only return one value(To return the position of a required integer in an array in this instance) I have tried to make use of pointers to try and return a value stating whether the array is sorted or not.This is my code : (It compiles perfectly but it does not produce any outputs)
Code:
#include <stdio.h> #define SIZE 10 size_t findNumber(int *sort, const int array[],int key,size_t size); int main(void){ int a[SIZE]; size_t x;
int myfunc( int a, int b, char * c ) char a = "(int)myfunc()"; char b = "(int,int,char*)" call(a, b, ...) // Function name and return type, params
I want to do function what registers forward what will get callback if the time is right. Basically then i dont need to edit and add extra functions into source files. I just have to include header and use register forward function. If there is anything close to this it would be perfect!
Every time I try to use the function SaveNewCD, it doesn't write to file correctly. It writes the ~, three characters, then goes into an infinite loop.
#include<iostream> #include<fstream> using namespace std; int SaveNewCD(); int OpenCD(); int main() { char ArtistName[25];
I'm having trouble returning a char array by a function, here's the code. The problem is the 'reverse' function, the purpose of the function is to send two char arrays, 'newline' containing the char array, reverse it and place it in the 'rev' char array then output it back in main, however the output remains blank so I assume there must be something wrong with the reverse function.
Code: #include <stdio.h> #define MAXLINE 10 int fgetline(char line[], int maxline); void copy(char to[], char from[]); void reverse(char forw[], char rev[], int arrsize);
I'm having a problem understanding something with pointers. I was trying to pass a pointer into a function in MSVC-2013, like
char* charptr; and then calling myfunct(charptr);
and then inside the function i would set charptr equal to another char ptr, simply like
charptr = anothercharptr;
But this actually caused a compile failure in MSVC, saying charptr is being used without being initialized. in Code::Blocks it just gives buggy output.
I solved this issue by calling the function like
myfunct(&charptr);
and declaring the function like myfunct(char**);
and then I had to dereference the charptr in the function when assigning it to another ptr, so *charptr = anothercharptr;
It seems like you should be able to just pass a ptr into a function and change its address to that of another pointer? My main question is really, what is the value of a pointer? I thought the value of a pointer was just the memory address it contains. But then I had to reference it to pass it into the function.
What is the difference between the value of the char* charptr written as either charptr and &charptr?
In the below program, When the getline function is called, it passes a char array of size 1000 by VALUE. It must have passed by value because there is no pointer or reference in the argument list of the getline function definition. And if that's the case, when exiting the getline function, isn't the s[] char array destroyed? And if it is destroyed, then when we reference line in the copy function, what are we actually copying?
#include <stdio.h> #define MAXLINE 1000/* maximum input line length */ int getline(char line[], int maxline); void copy(char to[], char from[]); /* print the longest input line */ main() {
I am using a small robotic-car that is controlled by writing C/C++ codes under Linux. I need to use a particular function from the library provided by the manufacturer. The relevant API documentation for the function is:
Returns: BASE_OK RS232 data acquisition success BASE_BASE_232_GETDATA_ERR RS232 data acquisition failure
I have trouble writing the relevant code in the main program that invokes this function. Here is a snippet of what I have tried:
# include "Baseboard.h" int main () { Baseboard _Baseboard; // Class name is Baseboard char *msg ;
[Code] ......
The part where I am uncertain is how to handle the char pointer "msg" in the declaration, function call and referencing. According to the documentation, the char pointer "msg" is the output of the function so I presume that is is somehow dynamically allocated. Am I handling the char pointer properly in the declaration, function call and referencing parts?
Another related question I have is: I am printing out the value of the variable "dummy". I always get 0 for it. Since the variable "dummy" is an enum of type BASEBOARD_ERROR_KIND which can take on two values (first value represents success and the second failure), it is alright to get a integer value of 0 for it if the function call was successful ? (I do not have much experience with using enums so this is a enum-related question on whether we can get an integer value representing the first enum value) .