C/C++ :: Atoi Does Not Work / Converting Cstring Vector Into Ints
Feb 18, 2015
I have saved the contents of an int vector to a txt file and the numerical data was converted into a c-string. Nov I need to import and read the contents back into my program but I have not been able to convert c-string numerical data back into ints.
View 1 Replies
ADVERTISEMENT
May 8, 2014
I am getting a string from the consle and that all works fine. I'm expecting a string of number, ie 123456.... I store that fine in my string object. I then need to take each individual number, ie 1, and put it in a vector then take the next number, ie 2, and put that in the next element in my vector.
Everything i've found and does eaither takes the entire string and stores it as an int, or takes the ascii representation of the number and stores that. How do I seperate each individual number and store them seperatly. below is a few different variations i've tried that doesn't produce my desired results.
cout<<"Please type the memory memory frames (numbers 0-9) to be used to simulate the input memory "<<endl;
cout<<"Your input: ";
string line="";
cin>>line;
cout<<"
Please wait while your input is processed and validated..."<<endl;
[code].....
the only thing i havn't tried yet is string streams and i don't necessarly like using them. Am i going to have to go that route? will that even work?
EDIT:I forgot to mention that this is being done on linux and then ported to unix.
View 7 Replies
View Related
May 16, 2013
I am having problems with converting a CString to an int and than doing checks on the int to see if it is in a particualr range.Below is what I am doing.
CString numstr = "28"
int num = atoi(numstr);
BOOL valid = TRUE;
if(num < -32,768 {
valid = FALSE;
}
For some reason when running the above code the if statement is executed but it should not be becasue 28 is not less than -32,768. Why this is happening, I am not seeing the reason for this at all!! The num variable is being assigned the correct value.
View 5 Replies
View Related
Jul 24, 2012
ShAltGr+A represents a foreign character in a font set.
How to make a CString variable for this so it can be displayed in a text editor programmatically?
Typing the combination of course works.
View 1 Replies
View Related
Sep 22, 2012
The below code is working fine in VS2008 and not working in VC6.0 (taking garbage values) this code is for converting hex values to string.
sending Input string is : 727332333263 required output: rs232c
DWORD AsciiToString(LPCTSTR f_chInputChar, LPTSTR f_chOutputChar) {
long ch;
int i,j;
TCHAR tmp[2];
int len = _tcslen(f_chInputChar);
[Code] ....
View 5 Replies
View Related
Feb 24, 2014
The code is supposed to take either an int or a string (and their respective vectors) and insert a given int or string into the vector in ascending order. My code works properly for ints, but it's having a problem with strings.
The order I get with the strings given is
penguin
banana
great
jungle
For some reason comparing penguin to banana/great doesn't give the expected result. The template attached only includes the function and the private vectors needed for the function.
template<class T>
class orderedList {
public:
void insert(const T& item);
private:
vector<T> list;
int total = 0;
[Code] ....
View 11 Replies
View Related
Aug 20, 2014
I want to convert the matrix to vector and vice verse.
View 1 Replies
View Related
Feb 15, 2012
I'm able to convert an integer to a vector<unsigned char> and back. However, when I try to use a nearly identical function designed for the long long data type, the last byte or two is broken.
Program code:
long long num = 9223372036854775551LL;
cout << "Before: " << num << endl;
vector<unsigned char> data = getBytes(num);
num = getLongLong(data);
cout << "After: " << num << endl;
Code for converting between vector<unsigned char> and long long:
Code:
vector<unsigned char> getBytes(long long value) {
int bytes = sizeof(value);
vector<unsigned char> data(bytes);
for (int i = 0; i < bytes; i++)
data.at(i) = (unsigned char)( value >> ((bytes-i)*8) );
[Code] ....
Output:
Code:
Before: 9223372036854775807
After: 9223372036854775552
Is there something special about long long that would prevent this from working? This problem doesn't happen with int.
View 3 Replies
View Related
Apr 20, 2013
Code:
#include <iostream>
#include <vector>
int main() {
std::vector<std::vector<double> > DV; //2d vector
std::vector<double>temp(8,0.0); //1d vector
[Code] .....
The conversion actually works but it does not give the expected the result. The output should be:
Code:
1 2 3
4 5 6
7 8
and it outputs:
Code:
123123123
View 5 Replies
View Related
Aug 25, 2013
How do I use string and atoi at the same time?
string scroes;
char input[SIZE];
cout<<" Enter your score" << endl;
cin.getline (input, SIZE);
scores = atoi (input);
View 1 Replies
View Related
Oct 12, 2014
Intead of using scanf("%d",&a) to take a input from the user,how to take a input using fgets(buffer, BUFFERSIZE , stdin) and atoi?
View 1 Replies
View Related
Sep 21, 2014
char intToStr(int a) {
int n, i, j, sign, set;
char r[10], s[10];
if (a[0] == '-')
sign = -1;
if (sign == -1)
[Code] ....
I have doubt at the time of handling of negative numbers at the time of converting to string ....
View 2 Replies
View Related
Aug 27, 2013
I am trying to convert a char to a CString, I have tried to use the CString.Format method but didn't work. I have a char(char holder[10]) and I want to see if holder is a certain string, say for instance SeaLevel. Below is the code that I also tried.
if(holder == "SeaLevel")
{
//do something
}
View 3 Replies
View Related
Jan 29, 2013
I need to circular right shift a cstring in C++
Let's say I have unsigned char test[10] = "HELLO!!!"; How would I go about circularly shifting this to the right? Inline assembly instructions would be ok too
View 6 Replies
View Related
Jul 9, 2014
I dont see any point of NULL in cstring. The code given below just outputs same as it would have done with NULL. My understanding is if size of char array is less than length of char array then null must be manually added?
#include <iostream>
using namespace std;
int main(){
char chr[0];
cin>>chr;//or if you use cin.getline;
cout<<chr<<endl;
return 0;
}
Enter something: hellowwwww
hellowwwww
Segmentation fault (core dumped)
why? for NULL char or something else?
View 1 Replies
View Related
Feb 19, 2014
Given a stack with an equal amount of even and odd numbers: 4, 22, 15, 3. The output should be in any order: [even], [odd], [even], [odd].
int main() {
Stack<int, 4> stk; stk.ClearStack(); int x;
for (int i = 0; i < 4; i++) {
cin >> x;
stk.PushStack(x);
[Code] ....
Output is:
Wed Feb 19 20:09:10 2014
4 7 5 22 //input
22 5 4 //output
Press any key to continue . . .
I know the logic fails if the first number is not even, but I cant seem to figure out another way to do it.
View 14 Replies
View Related
Feb 7, 2014
I have some paper work to do about a game I should be able to play with my class mates. We should be able to send and recive a struct concerning about the 'moves' of the pieces at the game. This struct is made of 4 ints, simple as that.
I had a previous paper work to do where I'd have to send ints and that was ok, but now that I have to send a struct I'm failing to do so. This is What I've tried:
//SERVER
struct message{
int code;
int piece;
int x;
int y;
}send;
bytes_sent=write(new_socket,&send,sizeof(message));
cout<<bytes_sent;
So far so good, I see 16 as bytes_sent's value.
On the other hand:
//CLIENT
struct message{
int code;
int piece;
int x;
int y;
}recive;
bytes_recvd=read(my_socket,&recive,sizeof(message));
cout<<bytes_recvd;
I always see 0 as the bytes_recvd's value.
View 3 Replies
View Related
Apr 7, 2013
I'm trying to compile the following and it doesn't work? How can I get the CString to initialize.
Code:
struct print {
int x; //row
int y; //col
int fid;
CString *data;
char *format;
[Code] .....
the char *format is not a problem, but compiler doesn't like CString *data;
tried CSting data and that also doesn't work, typecasting didn't work either?
View 14 Replies
View Related
Jul 9, 2014
Why would the following line of code cause an exception and how can I fix it? This is with Visual Studio 2013 and it is set to use "Multibyte Character Set". This is a very old program that I was updating.
Code: thepath = dadir + "*.csv";
Both dadir and thepath are type CString.
Prior to this line dadir looks fine when I look at it in the debugger but when I reach this line of code I get
First-chance exception at 0x0FA08EE1 (mfc120d.dll) in GAQUtilities2014.exe: 0xC0000005: Access violation reading location 0xFEFEFFC6.
View 5 Replies
View Related
Feb 13, 2013
I have gotten it to record the date and I can printf it either on the same function, or in the main(). However, one of the requirements I must adhere to is to printf the statement in a brand new function, but when I do that, it just doesn't work. Heres what I mean:
Code:
#include <stdio.h>
#define TICKER "LRCX"
#define INVESTMENT_AMOUNT "10,000.00"
//Prototypes
int getdate(int* month1,int* day1,int* year1,int* month2,int* day2,int* year2);
float getprice(float* BPrice, float* SPrice);
void printdate(int month1, int day1, int year1);
}
[code]....
View 3 Replies
View Related
Feb 18, 2013
I'm having trouble making a .obj loader at present I'm trying to load faces that are defined as follows:
f 1/1/1 2/2/2/ 3/3/3
So far I've separated the the three number groupings into three strings, I've had a few issues with stringstreams and would like a simple solution.
View 1 Replies
View Related
Mar 19, 2014
At first i had my int variables in global scope however i cant do the so im trying to pass my variables from my main to the void functions but cant.....
View 1 Replies
View Related
Jul 26, 2014
I am trying to generate some lists of permutations of ints but I can't make std::next_permutation work for me. The problem is I need to include permutations which don't use every number. For example take the array of numbers [1, 2]. I need an algo that will return:
1
2
12
21
Must work with up to 8 numbers.
View 5 Replies
View Related
Mar 12, 2014
I am trying to figure out the larger 2 out of 3 integers when i call them into a function from main program so far i have . How to write a simple function that will take 3 ints and find the sum of the higher 2?
Code:
int findsum(int a,int b,int c)// will find the highest int and return it to our main program {
int max,max2;// this sets our local variable max
// next we will find the larger of our first 2 variables
if( a>=b)
[Code]....
How to get the second highest number and add it to max...
View 4 Replies
View Related
Apr 4, 2014
Code:
//Class header
CString m_cstrArry[5];
Code:
//Class source
void Ctry4Dlg::OnInitDialog() {
m_cstrArry[0] = _T("TEXT 0 |");
m_cstrArry[1] = _T("TEXT 1 |");
m_cstrArry[2] = _T("TEXT 2 |");
[Code] .....
View 8 Replies
View Related
Sep 13, 2013
I have a non-MFC static library which I share between a number of different projects, some non-MFC and some MFC. Currently the static library uses a typedef of std::wstring and std::string for UNICODE and non-UNICODE builds.
After discovering it's possible to use CString in non-MFC applications, by including atlstr.h header, I decided I'd rather that than using stl strings and having to keep converting between the different types. However, I seem to be struggling with linker errors when linking the library with a MFC application.
Can I create a non-MFC static library using CString from atlstr.h and link it with a MFC application?
View 11 Replies
View Related