C++ :: Char Isn't Transferring In Function
May 14, 2014
In my classification function, the char isn't transferring to main. Am i suppose to make it a string. Or perhaps something else i messed up on
#include <iostream>
using namespace std;
double validity(double, double, double);
double classification(double, double, double, char);
[Code]....
View 10 Replies
ADVERTISEMENT
Feb 1, 2014
In the function *expandArrayList and *trimArrayList I need to allocate either more memory or less memory to the given array. Right now I am using malloc on a new array and then transferring the elements of the original array to the new array, freeing the original array, and then reassigning it to the new array so it's size and capacity are either bigger or smaller than the original. I feel like there has to be a simpler way to do this with either realloc or calloc, but I cant find sufficient information on either online. Would I be able to use either to make this easier and the code cleaner?
Also, these are character arrays that contain several character arrays inside them, so I was wondering what the best way to transfer the contents of one array to the other would be. I have gone between
Code:
//example
for (i=0; i<length; i++){
newarray[i] = oldarray[i];
}
and
Code: for (i=0; i<length; i++){
strcpy(newarray[i], oldarray[i]);
}
but I'm not sure which one (if either) should work.
The 'ArrayList.h' file that is included contains the structure ArrayList, as well as the function prototypes for the functions listed below.
Here is the structure in ArrayList.h:
Code:
#define DEFAULT_INIT_LEN 10
typedef struct ArrayList {
// We will store an array of strings (i.e., an array of char arrays)
char **array;
[Code] ....
Here is my code:
Code:
//included libraries
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ArrayList.h"
//Create arraylist
[Code]....
View 3 Replies
View Related
Feb 11, 2013
I have some problem with the ssize_t sendfile function.
ssize_t sendfile(int out_fd, int in_fd, off_t *offset, size_t count);
The error:
Lesson_4_1A_Home_work.c:84:24: error: expected declaration specifiers or ‘...’ before string constant
Lesson_4_1A_Home_work.c:84:37: error: expected declaration specifiers or ‘...’ before string constant
Lesson_4_1A_Home_work.c:84:63: error: expected declaration specifiers or ‘...’ before ‘strlen’
Code:
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <sys/sendfile.h>
#include <sys/types.h>
[Code]....
View 3 Replies
View Related
Jun 13, 2014
I am trying to transfer information of Variables. How to get this to work and everything I follow shows that this SHOULD work but some reason does NOT work... I
What I CAN get to work is if I put frm.show(); on one specific section that ONE section will show up... so I tried putting all of the variables at the end button to get them to show up with the one Frm.show and it still only does the very last one and the rest are just blank I dont really understand as to why.
Also if I put a FRM.show at each step it will just keep creating a new instance of form 2 each with a different line that is changed.
Form1 code
public Form1() {
InitializeComponent();
} public void Enter_Click(object sender, EventArgs e) {
Form2 frm = new Form2();
Employee FirstName = new Employee();
[Code] .....
Form2 Code
public partial class Form2 : Form {
public Form1 frm1;
public Form2() {
InitializeComponent();
}
View 8 Replies
View Related
Feb 22, 2015
I can not do transferring data to textboxes from database.
="c#">using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace WindowsFormsApplication1{
[code]....
I got the error this line:
read = cmd.ExecuteReader();
View 3 Replies
View Related
Mar 10, 2013
I'm trying to put file data into members of a class. Remember to type in the file name you want to open. Cool feature right? I just had Dbase.txt so I chose that.
Fixed stuff in the .txt. Now I need to figure out why it only does 1 set and then ends.
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
using namespace std;
class INFO {
[Code] .....
Dbase.txt:
Bob
Guy
Programmer
M
9999.99
40
------------------
Little
Guy
Little Brother
M
0.0
3
------------------
View 14 Replies
View Related
Mar 20, 2015
I'm transferring a unicode string from one program to another with UTF-8 encoding.
Program that is sending:
Code:
// Convert path
std::wstring_convert<std::codecvt_utf8<wchar_t>> utf8_converter;
CString arg = L" /PATH="" + CString(utf8_converter.to_bytes(path).c_str()) + L""";
Program that is retrieving:
Code:
// Restore original path
std::wstring_convert<std::codecvt_utf8<wchar_t>> utf8_converter;
std::wstring path = utf8_converter.from_bytes( argument );
Everything has worked fine, until running on a Japanese edition of Windows.
The "byte path" then looks something like "C:¥Users¥d✝?✝a ,?¥AppData¥Local¥Temp¥file.txt".
"from_bytes()" will throw an std::range_error exception "bad conversion".
The program works fine when working with Japenese writing inside paths in the English edition.
What could be causing the "bad conversion"?
View 10 Replies
View Related
Feb 19, 2014
Is this possible?
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!
View 5 Replies
View Related
Sep 4, 2013
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;
[Code].....
View 11 Replies
View Related
Aug 3, 2013
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];
[Code] .....
View 5 Replies
View Related
Mar 2, 2015
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);
[Code] .....
View 1 Replies
View Related
Jun 7, 2013
Now I am stuck with getting const char* array from function to main.
Code:
const char* values[3];
strings_to_array()
printf("%s
", values[1]);
printf("%s
", values[2]); function: Code:
const char* strings_to_array()
}
[code]....
First, I cant get strings printed out in main.
Second, is here way to get number of such elements which array contains like higher languages have "count" or "ubound" or such?
Third, next function which need that array assumes that array of const chars* is 1 based. Can that be set in C or here are allways zero based arrays?
View 1 Replies
View Related
Jan 2, 2014
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?
View 1 Replies
View Related
Nov 23, 2013
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() {
[Code] .....
View 3 Replies
View Related
Feb 5, 2014
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:
BASEBOARD_ERROR_KIND ZMP zrc :: :: :: Baseboard GetRS232Data (char * msg )
RS232 data acquisition.
Argument:
[Out] msg Address of the acquired data.
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) .
View 2 Replies
View Related
Jun 1, 2013
How to pass the char something[8][8] for example to function void ( char pass.....)???
View 7 Replies
View Related
May 15, 2014
I want to return a char array to the main() function, but its returning garbage value.
#include<stdio.h>
//#include<conio.h>
#include<string.h>
char* strtrmm();
int main() {
char str1[100],c1[100];
[Code] .....
View 5 Replies
View Related
Feb 4, 2014
Why does this code doesnt work?
#include <iostream>
#include <cstring>
#include <string>
using namespace std;
class my_string {
char* ptr;
[code] ....
View 1 Replies
View Related
Jan 30, 2013
I have always written like a>='0'&&a<='9'&&a>='a'&&a<='z' in loops etc, but no more. Basically add whatever you want to condition, and if you want point a to point b just separate them with a '-' sign. Simply
while(!isCharInside(x,"|a-zA-Z0-9.*/=|-|")){/*code*/}
bool isCharInside(char check,string condition="a-zA-Z*/+=|-|0-9"){
for(unsigned int x=0,z=getLenght(condition);x<z;++x){
if(condition[x+1]=='-'&&(condition[x]!='|'&&condition[x+2]!='|')){
if(condition[x]>condition[x+2])swap(condition[x],condition[x+2]);
for(;condition[x]<=condition[x+2];++condition[x]){if(condition[x]==check)return true;};x+=2;}
else if(check==condition[x])return true;
}
return false;}
View 1 Replies
View Related
Oct 6, 2012
If we are using strcpy() for copying the string. As we are passing pointers to it It will copy the string & no need to return the string .This function will finely work with return type as void then why Ritchie has used it as char* strcpy()?
View 4 Replies
View Related
Dec 8, 2013
can I operate a char string to a function at C programming?
View 1 Replies
View Related
Mar 24, 2015
I have the following code, but it crashes on the "data = " line...
Code:
void Test(string& data) {
unsigned char* msg = (unsigned char*)malloc(MAX_LENGTH));
...
data = string(reinterpret_cast<const char*>(msg), MAX_LENGTH);
}
I know I could just return string, but what is wrong with this code that is making it crash?
View 6 Replies
View Related
Nov 5, 2013
I am required to write a program which, when given an nxn 2D array of char, and the specified coordinates of a specific point in that array, returns thelargest number of horizontal, vertical or diagonal contiguous (side-by-side) sequence of points of that same char value that intersects with the given point.
The way I took on this problem was to:
1) First find out the number of points with the same char value up, down, right, left, north-east, north-west, south-east, and south-west of the given point.
2)Add up+down+1(the one is for the point itself), north-west+south-east+1, etc...
3) Finally I compared the four values (updown, rightleft, NESW, NWSE) and returned the largest one.
Well, that's how the program is supposed to work in theory but as you can probably guess it doesn't work. In addition to telling me what I'm doing wrong, is there a simpler way to do what I am trying to accomplish?
Here's the code:
Code:
int findLongest(char **board, int n, int row, int col)
{
char current;
int rightleft, updown, NESW, NWSE;
int r, c, c1=0, c2=0, c3=0, c4=0, c5=0, c6=0, c7=0, c8=0, d;
int t1=1, t2=1, t3=1, t4=1, t5=1, t6=1, t7=1, t8=1;
current=board[row][col];
//check Above: col remains the same
for(r=row-1;r>=0||t1!=0;r--)
//with the condition r>=0 I made sure not to accidentally check values outside of the array
[Code]...
View 1 Replies
View Related
Feb 17, 2014
This code ran well until i added in the ToLower function which is supposed to convert the char array string to lower case (based off ascii strategy -32). correct this function so it converts string to lower case and doesn't get errors.
#include <iostream>
#include <string>
using namespace std;
const int MAX = 81; //max char is sting is 80
void ToLower(char s[]);
int main(){
string y_n;
[Code]...
View 1 Replies
View Related
Oct 10, 2013
I have been assigned the following task and I am having difficulty in getting it to compile. The compiler is stopping at line 27 but I don't no what the error is.
The task is as follows:
Write two functions with the following function prototypes:
int my string len(char str[])
void my string cat(char dest[], char src[], int dest size)
Both functions should take zero-terminated strings as input. The first function should return the length of the string to the calling function. The second function should take a source and a destination string and the total size of the array pointed to by dest. It should then concatenated the source string onto the end of the destination string, if and only if the destination string has the capacity to store both strings. If the destination string does not have the capacity it should not alter either, print and error, and return to the calling function. Demonstrate the use both the above functions by using them in a program in which you initialise two character arrays with two strings, print out their length, print out the combined length, and print out the combined string
And this is my code so far:
/* A program to demonstrate string concatenation */
#include <iostream>
#include <string.h>
using namespace std;
int my_string_len(char str[]){ // function to calculate length of a chracter array
int len = 0;
[Code] ....
View 8 Replies
View Related
Aug 31, 2014
I had problem in comparing 2 char vairable in check function
if(room_no==r)
variable r take input from user and compare to room_no read from file.
#include<iostream>
#include<conio.h>
#include<fstream>
#include<stdio.h>
#include<dos.h>
#include<string>
#include<stdlib.h>
[Code] .....
View 2 Replies
View Related