C++ :: Convert Char To Time?
Aug 2, 2013
I am trying to convert char to time and I found the following code. But it gives me a -1 on "converted" instead of time.
#include <stdio.h>
#include <time.h>
#include <iostream>
using namespace std;
[Code].....
View 7 Replies
ADVERTISEMENT
Jun 3, 2013
I have a file which contains a year and the name of an associated file to be read. I need to extract the data in the txt file and perform some calculations.
( year data file)
2004 2004data.txt
2005 2005data.txt
2006 2006data.txt
Here is what I do. I first declare "char yeardata" and then pass "2004data.txt" to it. Then I call yeardata in ifstream to extract the data inside the file "2004data.txt". The problem is that char yeardata is not constant so I cannot pass the file to it. It doesn't work if I change "char yeardata" to "const char yeardata".
Code:
int oldnewcomp_temp(char* lcfile) {
using namespace std;
int year;
char yeardata;
[Code] ....
View 12 Replies
View Related
Sep 1, 2014
I am converting unix timestamp to datetime format like this:
static readonly DateTime UnixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
static readonly double MaxUnixSeconds = (DateTime.MaxValue - UnixEpoch).TotalSeconds;
public static DateTime UnixTimeStampToDateTime(double unixTimeStamp) {
return unixTimeStamp > MaxUnixSeconds
? UnixEpoch.AddMilliseconds(unixTimeStamp)
: UnixEpoch.AddSeconds(unixTimeStamp);
}
use it:
Console.WriteLine("From UNIX do datetime 1300123800440 : " + UnixTimeStampToDateTime(1300123800440));
output: 14.03.2011 5:30 PM
Now i would like to have function which convert it back to unix timestamp but unfortuently my new function is cutting down last 3 digits for instance:
public static long UnixTimestampFromDateTime(DateTime date) {
long unixTimestamp = date.Ticks - new DateTime(1970, 1, 1).Ticks;
unixTimestamp /= TimeSpan.TicksPerSecond;
return unixTimestamp;
}
after use of it i am retrieving:
Console.WriteLine(UnixTimestampFromDateTime(Convert.ToDateTime("14.03.2011 5:30 PM")));
result:
1300123800
View 14 Replies
View Related
Jun 13, 2013
I have total time in seconds (say 2500 seconds). I want to store this time in CTime or CTimeSpan format.?
How to do this.?
View 2 Replies
View Related
Mar 28, 2014
I would like to have a program with a 5 mb string embedded in it kind of like this:
Code:
const char *c;
c = (const char*)"BEGIN_STRING_HERE, (5 MB of arbitrary values here)";
Is it possible to generate this string at compile time? Maybe with a macro? I'm trying to avoid a source file with a 5 mb string in it.
View 3 Replies
View Related
Nov 9, 2013
I am writing a basic keylogger and i want to add data to log file, but it says that i cant convert char to int. Everything else works fine.
Code:
#include <iostream>#include <windows.h>
#include <stdio.h>
#include <time.h>
using namespace std;
[Code] ....
View 3 Replies
View Related
Nov 24, 2014
Example
char A[4]
gets(A) --> 1234
View 11 Replies
View Related
Jan 24, 2015
if we have int x = 5; and we want to convert x which is == 5 to char so for example char number = x doesnot work i understand why , but how to convert it ?
View 14 Replies
View Related
Jan 14, 2015
I am trying to use to save the current date and time into a char array using this code:
char current_time(char *date){
time_t result = time(NULL);
date = ctime(&result);
return *date;
}
main{
[Code]...
now when I output the date char array into a txt file I only get gibberish.
View 6 Replies
View Related
Apr 30, 2013
Is there anyway to convert std::string to char*?
Like:
std::string x="hello world";
char* y=x;
View 6 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
Jul 5, 2013
I have this code working:
char tmp_wku[3];
tmp_wku[0]=0x01;
tmp_wku[1]=0x9D;
tmp_wku[2]=0x62;
char tmp_com[11];
[Code] ....
This sends the buffer to a LIN modem. My question is: can this be done better. If I have a astring of hex numbers like "09 98 88 55 42 FF 00 00 FF BD 89". How could I send this without manually makng a char with hex numbers?
View 1 Replies
View Related
Jan 1, 2015
when I was looking for a way how to convert char into numeric value for std::cout I found some old discussion with this statement: Operations on unsigned int are typically faster than on unsigned char, because your processor cannot fetch single bytes but has to get at least a multiple of 4 and mask out the other 3 bytes. Is this true? By using smaller (in bytes) variable I actually slow down my program? I always thought that it is a good practice if I use the smallest variable which will do the work. Is it also dependent on a compiler and OS?
View 2 Replies
View Related
Feb 22, 2014
I want to avoid converting the char[] into a string as an intermediate step, since I'm trying to write some "string" parser helpers which don't allocate a bunch of different strings onto the heap. (whole point of this little project is to reduce GC pressure in applications that do alot of string parsing).
basically if I have a char[] that contains {'1','2','3'}, I'd want to to be converted into 123.
I tried messing around with the stackalloc operator in C#, but its illegal to stackalloc a string unfortunately. I also googled around for converting a char[] into a numeric value, but all the solutions convert each individual char into their ASCII code, or convert the char[] into a string as an intermediate step.
View 12 Replies
View Related
Feb 20, 2015
I am trying to compile the following C code in C++ with visual studio 2010:
Code:
#include <windows.h>
#include <stdio.h>
void test(FARPROC addr) {
__try {
addr();
printf("ok
[Code] ....
But I get the compilation error: main.cpp(25): error C2440: 'type cast' : cannot convert from 'char [4096]' to 'FARPROC'
How would I make this compile in C++?
View 3 Replies
View Related
Jun 7, 2012
I want to convert int to char array for get the total of digits like this..
Code:
int total;
char charnum[2] = (char)total; //this is the problem
int num = 0;
for (int i = 0; i <2; i++)
{ num += charNum[i] -48;}
cout << num;
If total was 42 i want to get output as 6. for this purpose i want to convert int to char.
View 7 Replies
View Related
Oct 15, 2013
Currently I have:
Code:
char my_array[4] = { '1', '2', '3', '4' };
how do I convert the above to a string of: "1234"
View 6 Replies
View Related
Mar 8, 2013
.I have this string that I need to convert into a 2d char array like this:
String str= "A,E,B,I,M,Y#N,R,C,A,T,S";
I know how to use delimiter and split string and I know how to convert but only from string to char[].I need something like this:
Input: String str= "A,E,B,I,M,Y#N,R,C,A,T,S";
Output: [A] [E] [B] [I] [M] [Y][N] [R] [C] [A] [T] [S]
View 6 Replies
View Related
Feb 21, 2013
Without lossing information?
View 14 Replies
View Related
Mar 6, 2015
How to convert char array into double?,i.e. store char array values into a single double variable. Below is the code that i'm working. Im extracting the value "2255.1682" from char array gpsdata1. I used while loop, extracted the value and stored in "myChar", but i want to store it in double variable "lat1".
Code:
#include <stdio.h>
#include <stdlib.h>
int main(){
unsigned char gpsdata1[]="$GPGGA,091310.000,2255.1682,N,11356.3605,E,1,4,1.62,164";
char myChar;
double lat1;
[Code] .....
View 5 Replies
View Related
Oct 4, 2014
How do I convert a variable of type unsigned char to string.
View 9 Replies
View Related
Jan 27, 2015
i want to convert in loop for example this
char number[]="54465465445646848640";
and in loop convert these element to int one by one.
View 1 Replies
View Related
Jun 17, 2014
How can you convert int type to const char*
View 2 Replies
View Related
Apr 29, 2015
How do I convert a string of unknown length to a char array? I am reading strings from a file and checking if the string is a Palindrome or not. I think my palindrome function is correct, but do I do something like char [] array = string.length(); ??
#include <iostream>
#include <fstream>
#include <string>
#include <cctype>
[Code].....
View 2 Replies
View Related
Jan 20, 2014
i found a lot about how to convert int to const char * but non of them explain correctly or sometimes dont even work.
Here is my code:
#include <stdio.h>
#include <cstdlib>
using namespace std;
int main () {
int i =0;
char c1 =0;
char c2 =0;
[code]....
View 15 Replies
View Related
Jun 25, 2014
I am using eeprom my integer data store in that int =1234 it stores ony character in eeprom. one character is 12 and other one is 34
View 2 Replies
View Related