![]() |
|
Question about C programming - Printable Version +- Southperry.net (https://www.southperry.net) +-- Forum: Social (https://www.southperry.net/forumdisplay.php?fid=14) +--- Forum: Rubik's Cube (https://www.southperry.net/forumdisplay.php?fid=58) +--- Thread: Question about C programming (/showthread.php?tid=15034) |
Question about C programming - Fiel - 2009-08-14 I have an "unsigned char* unpackedZlibBlock;" string, but I want to be able to read values from that string (ints, doubles, floats). So let's say that the first four bytes of this string is supposed to be interpreted as an integer. What would be the best way to fetch those four bytes from the string? "strncpy"? "memcpy"? Question about C programming - Spaz - 2009-08-14 Fiel Wrote:I have an "unsigned char* unpackedZlibBlock;" string, but I want to be able to read values from that string (ints, doubles, floats). So let's say that the first four bytes of this string is supposed to be interpreted as an integer. What would be the best way to fetch those four bytes from the string? "strncpy"? "memcpy"?unsigned char* unpackedZlibBlock = getUnpackedZlibBlock(); unsigned char* zlibBlockPos = unpackedZlibBlock; unsigned int numberOfChinchillas = *((unsigned int *) (zlibBlockPos)); zlibBlockPos += 4; You can just cast the unsigned char pointer to an unsigned int (or whatever) pointer. Question about C programming - Fiel - 2009-08-14 Perfect. Just what I needed. Thank you very much. Question about C programming - Fiel - 2009-08-14 I have another question and I didn't want to bother making a new topic for it: if I have 'a' assigned to "char foo", what command can I give such that "char* bar" equals "aaaaaa"? How do I copy strings like that without using a loop? Question about C programming - kingdj333 - 2009-08-14 O_o, english plox. you guys use numbers to much. And sometimes letters. Question about C programming - Russt - 2009-08-14 ^ There's only one number posted in this thread, lol. This isn't a thread about English
Question about C programming - Turtally - 2009-08-14 kingdj333 Wrote:O_o, english plox. Isn't the whole point of this thread to discuss a different language? Question about C programming - Fiel - 2009-08-14 Nevermind. I just figured it out. Question about C programming - Heidi - 2009-08-14 kingdj333 Wrote:O_o, english plox. So you ask for english, then say that they sometimes use letters too much? Isn't english made up of letters? Seriously though, if you read the thread title it says "Programming". SURELY you would have at least a small idea what that is, and if not you probably could have realised by seeing this thread/ other threads with programming in them. And the only number I can see is "zlibBlockPos += 4 o_o Question about C programming - Dusk - 2009-08-14 lol it's a C programming thread, if you can't tell a char* from an operator just don't bother posting. I'm interested in what the solution was to your second question, Fiel. Question about C programming - Fiel - 2009-08-15 Well, it's a cheating way of doing it. Since I'll eventually be using the char array to write to a file, just do this... fwrite(myCharArray, 1, 7, MyFile); fseek(MyFile, -7, SEEK_CUR); //define a new char type, then fread it |