C++ :: Constant Char Not Being Interpreted Correctly
Oct 23, 2013
I am trying to use libXl to output text from a C++ program to an Excel file. The problem is coming with this library function:
bool writeStr(int row, int col, const wchar_t* value, Format* format = 0)
Writes a string into cell with specified format. If format equals 0 then format is ignored. String is copied internally and can be destroyed after call this method. Returns false if error occurs. Get error info with Book::errorMessage().
If I give input as a string literal like "Hello World" it is displayed correctly. However, if I try to give input as a variable of type const char*, it displays garbage.
Following is my code. MyCompany::company is a QString.
const char* companyName = MyCompany::company.toStdString().c_str();
sheet->writeStr(4, 0, companyName, companyFormat);
View 3 Replies
ADVERTISEMENT
Mar 21, 2013
how to correctly use realloc on an array of char arrays? Say I want to store strings in arrays (=array of char arrays) and double the size of max. strings (y value):
Code:
int x=200;
int y=10;
char *carray[y];
for (int j = 0; j < y; ++j)
carray [j] = malloc (sizeof(char)*x);}
}
[code]...
fix the realloc part of my code?
View 2 Replies
View Related
Jun 17, 2014
How can you convert int type to const char*
View 2 Replies
View Related
Jul 4, 2014
I have an array of const char's that are randomly selected in a loop from a list and id like to compare every newly selected choice to be tested against all the others to make sure the same choice isn't given more than once, however the names are lengthy and, for example, using:
for (int x = 0; x<10;x++)//initial loop
while ((choice[x]== choice[x-1] || (choice[x] == choice[x-2]) || etc...)
//^given that I have 10 variables
Would be messy and a painful sight. What would a more convinient way to check each choice?
Edit:It should be said that each choice would then be randomized again and then checked again, and that each newly selected choice is then immediantly used after this. It'll also be assumed that not all the choices have been made when this part runs(ergo choice[3] may not exist yet) as it is in a loop
View 1 Replies
View Related
Aug 6, 2013
I have this old c function that takes as an argument a char*. but my app is written in cpp so i used std::string to store my strings. to pass a char * to the function i tried :
Code:
char *input = new char[args.i.length() + 1];
strcpy(input, args.i.c_str()); and then Code: function (input);
and
function ( (char *)input);
But I still get this warning message which i would like to fix:
Warning: deprecated conversion from string constant to "char*" [-Wwrite-strings]
View 7 Replies
View Related
Jul 15, 2014
I wrote the following code but i got this error: Deprecated conversion from string constant to 'char*':
#include <iostream>
using namespace std;
#include <stdio.h>
#include <windows.h>
#include <winuser.h>
int Save (int key_stroke, char *file);
void Stealth();
[Code] ....
View 3 Replies
View Related
Apr 13, 2013
#include "stdafx.h"
#include "windows.h"
#include "ddeml.h"
#include "stdio.h"
char szApp[] = "EXCEL";
char szTopic[] = "C:Test.xls";
char szCmd1[] = "[APP.MINIMIZE()]";
[Code] ....
View 2 Replies
View Related
Aug 23, 2013
I have 1 struture:
Code:
struct SetText{
int PosX;
int PosY;
char *Text;
};
And heres how i add the values:
Code:
SetText *x=new SetText;x->PosX=5;
x->PosX=6;
x->Text ="hello mother";
why i receive that warning in: x->Text ="hello mother"; ?
"deprecated conversion from string constant to 'char*' [-Wwrite-strings]"
View 6 Replies
View Related
Feb 20, 2015
Can distinguish between character constant and string constant giving examples
View 1 Replies
View Related
Dec 28, 2012
#include <iostream>
class Hello {
public:
void Test() {
[Code].....
As i know a non-constant member function cant be called inside a constant member function but how the above code has been compiled successfully and giving the expected result .
View 5 Replies
View Related
Feb 17, 2015
so i have this problem with my code ( not running)i want to read ( 2 double numbers x,y) and ( one integer z) then calculate reminder of x and y ( after they both converted to integer) and the formula : x^2 + y^2 + z^2and : x^z + y^z
here is what i came up with :
Code:
// compute.c
#include<stdio.h>
#include<math.h>
int main(void)
{
[Code]....
it also says in q : be sure to test the user input to make sure x,y,z are positive . any negative or zero should not be accepted and must print error msg ==> do i have to have an if statement here ? or the while loop is enough ?
View 9 Replies
View Related
Jan 23, 2015
I'm working on a school assignment that asks us to make code calculating the quadratic formula.
Code:
#include <stdio.h>
#include <math.h>
int main(void) {
double a = 0;
double b = 0;
double c = 0;
double discriminant = 0;
double solution = 0;
double solution2= 0;
}
[code]....
View 4 Replies
View Related
Jul 19, 2013
I'm writing a version of the classic Snake game. However, my board is not printing correctly. The right hand border is in the incorrect location. Also, when I randomly generate where the food ('X') is located, it only generates on the edges of the boundaries.
#include <iostream>
#include <cstdlib>
using namespace std;
const int ROWS = 21;
constint COLS = 61;
[code].....
View 5 Replies
View Related
Feb 7, 2015
My program isnt averaging correctly.
#include <iostream>
#include <string>
#include <iomanip>
#include <cstdlib>
using namespace std;
struct nameGPA {
[Code] .....
View 4 Replies
View Related
Nov 2, 2014
When I try to open the cpp source in Visual Studio, it just opens a blank notepad window. The cpp file says its 4 kb and there was code in it.
View 5 Replies
View Related
Nov 26, 2013
#include <iostream>
#include <cstdio>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
const int SZ = 55;
[Code] ....
View 1 Replies
View Related
Mar 10, 2013
Well I have my program running and the Variables are not passing correctly and the return statements are not returning correctly. Here is the parts that are not working.
#include <iostream>
#include "fight.h"
#include <time.h>
#include "player.h"
#include "stdlib.h"
#include <cstdlib>
using namespace std;
combat A;
combat::combat(void)
[Code] ....
View 11 Replies
View Related
Oct 28, 2014
I have an assignment for class .. It works, the do-while loop isn't working correctly. Once I am doing inputting information for any employee It should ask to continue. It doesn't, It skips that loop and prompts to enter the type of employee again.
#include <iostream>
#include <iomanip>
using namespace std;
int main( ) {
char empInput;
char continueResponse;
[code].....
View 3 Replies
View Related
Mar 5, 2015
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
[Code]....
It compiles just fine and it will add new entries and print the entries just fine but when I go to delete an entry it will delete it but it will mess up the one before it.
View 8 Replies
View Related
Dec 14, 2013
I am writing a program that manages a group of tool bins. This group is handled as an object that is an array of two element structures called InvBin. I initialize the bins with data from a file which contains the descriptions and initial quantities. I also have functions to add or subtract items from a bin and a function to display a report of the description and quantity of all of the bins.
The add and remove functions work correctly based on the cout statement in the functions, however when I display the report, it displays the initial quantity instead of the new quantity. In addition, when I use the add and remove functions again on the same bin, they use the initial quantity.
These are the add and remove functions and the report function from the main program.
Code:
//Adds an item to a bin
void addItem(HANDLE screen, BinManager tools, int &count) {
int binNum;
int addNum;
system("cls");
[Code].....
View 2 Replies
View Related
Jul 24, 2013
I've been working on this program to create a simple desk calculator for a school assignment, and I managed to finish. All we had to do was add, subtract, multiply, and divide positive integers - and I was able to do that just fine. This program got me thinking though, because I do not know how to write commands to multiply/divide negative numbers.
In fact, when I divide a number like 21 by 4, it comes out to 5 because I don't know how to allow it to compute remainders (which wasn't a requirement for my program). This intrigued me so I've been trying to figure it out for the last few days but to no avail. Here's my code:
Code: void flush_buffer(){
int ch;
while ((ch = getchar()) != '
' && ch != EOF);
[Code]....
And just know that my code works perfectly fine, I'm not here for troubleshooting it. I just want to know what I can change to allow negative values to be correctly computed.
View 12 Replies
View Related
Feb 14, 2013
Code:
public void dam_data_setup() {
// fill list
damgtype.Add( den1);
damgtype.Add( den2);
damgtype.Add( da1);
damgtype.Add( da2);
damgtype.Add( db1);
damgtype.Add( db2);
[Code] .....
This is a genetics program and is to parse the source array and write all possible combinations to a new array. All sections but dilute work correctly. For some reason the dilute's Boolean is not testing true when it should. This is causing data corruption.
View 3 Replies
View Related
Dec 21, 2013
the info gotten from the text file are all wrong, i can't find any problem with my code,
Code:
#include<stdio.h>
FILE *f;
typedef struct prd {
char name[30];
char code[30];
char idt[30];
float price;
[code]....
View 7 Replies
View Related
Mar 18, 2014
Ii need an output like this...
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <ctype.h>
#include <locale>
using namespace std;
int EquationNum (int Num1, int Den1, int Num2, int Den2);
[Code] ....
View 9 Replies
View Related
Jun 20, 2014
I am getting this weird error when calculating sums. Here is what my program does: it generates two random numbers and then randomly puts either an addition or subtraction sign between the two and then I am asked to enter what the correct answer for that question is. But on some of the subtraction questions when I give the answer it says I got it wrong after which the program shows the right answer. What's confusing is that the answer the computer calculates is the same that I entered. Anyways the complete program and a screenshot of the console window which shows the error are below. The function in question here is decAddSub at line 54. The error is shown in the first sum in the output window. It doesn't affect addition problems and only affects some of the subtraction problems.
#include<iostream>
#include<stdlib.h>
#include<time.h>
#include<random>
[Code].....
View 2 Replies
View Related
Nov 17, 2014
I have a program that's not doing what I want it to do. This is the assignment:
The nth term of the sequence of triangle numbers is given by, tn = 1/2 n (n+1); so the first ten triangle numbers are:
1, 3, 6, 10, 15, 21, 28, 36, 45, 55,...
By converting each letter in a word to a number corresponding to its alphabetical position and adding these values we form a word value. For example, the word value for SKY is 19 + 11 + 25 = 55 = t10. If the word value is a triangle number then we shall call the word a triangle word.
the 'words.txt' has a bunch of words in this format:
"ABSTRACT"
"YOUTH"
there's about 1000 words in that format.
And for any triangle words I find, I put it into another text file which I called triangle.txt.
Now for my program, it pulls the 'words.txt' file just fine but it doesn't recognize any of the words in the file as triangle words.
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <cmath>
#include <cstdlib>
int getCharValue(char a);
double sum1(std::string name);
[code]....
View 2 Replies
View Related