User Profile

Collapse

Profile Sidebar

Collapse
mjbauer95
mjbauer95
Last Activity: Sep 11 '10, 12:58 AM
Joined: Jan 2 '09
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • mjbauer95
    started a topic Converting 8 bytes to integer
    in C

    Converting 8 bytes to integer

    I am working with a binary file and I have 8 bytes that I want to convert to an integer.

    This way works:
    Code:
    unsigned char buf[1024];
    long long value;
    
    value = ((long long)buf[0]<<56) | ((long long)buf[1]<<48) | ((long long)buf[2]<<40) | ((long long)buf[3]<<32) | (buf[4]<<24) | (buf[5]<<16) | (buf[6]<<8) | buf[7];
    
    printf("%lld\n", value);
    ...
    See more | Go to post

  • mjbauer95
    started a topic How do you declare a data type with 1 bit size?
    in C

    How do you declare a data type with 1 bit size?

    How can you declare a data type with 1 bit size? So I can have a true boolean and not just an int or enum.
    See more | Go to post

  • george666
    george666 posted a Visitor Message for mjbauer95
    Yes, there are built-in functions.
    You can ask on Professional Windows programming group (in C) :
    news://nntp.aioe.org/comp.os.ms-wind...ogrammer.win32
    where it has often been discussed
    See more | Go to post

  • mjbauer95
    started a topic Reading Hexadecimal
    in C

    Reading Hexadecimal

    Sorry for another post but I'm having trouble with something else.

    What is the best way to read and store a hex file in the buffer? Char does not seem to work properly for me.
    See more | Go to post

  • mjbauer95
    replied to Hexadecimal to Binary
    in C
    Thanks I knew it was something like that but it's nice to have the bytes.com community's help here on stuff that is really hard to find on Google.
    See more | Go to post

    Leave a comment:


  • mjbauer95
    started a topic Hexadecimal to Binary
    in C

    Hexadecimal to Binary

    Are there any functions out there to convert Hex to Bin?

    Like if I had 0xA0 it would convert it to 0b10100000.

    But I mainly want this so I could get the say the first bit like:
    Code:
    bool getHex(char * hex, int place);
    And I could write getHex(0xA0, 16) and it would return true.
    See more | Go to post

  • mjbauer95
    started a topic Memcpy vs. =
    in C

    Memcpy vs. =

    What is the difference between memcpy() and just using the = symbol, as in:
    Code:
    char * str1;
    str1 = "TEST.";
    char * str2;
    str2 = str1;
    vs.

    Code:
    char * str1;
    str1 = "TEST.";
    char * str2;
    strcpy(str2,str1);
    What are the advantages of using strcpy because that seems to be the "right" way?
    See more | Go to post

  • mjbauer95
    replied to Split function in C
    in C
    How do you return both split[0] and split[1]? I assumed split[2] would be the whole array.
    See more | Go to post

    Leave a comment:


  • mjbauer95
    started a topic Split function in C
    in C

    Split function in C

    Here is my function to split 2 strings.
    It has no errors but the function returns an array of lots of random characters.

    Code:
    char * split(const char * original, const char * search) {
        char split[2][1024];
    
        int i = 0;
        int j = 0;
        int flag = 0;
        int r = 1;
    
        for (i = 0; i<strlen(original); i=i+1) {
            if (!original[i]) break;
    ...
    See more | Go to post

  • mjbauer95
    replied to File reading
    in C
    Does the buffer have to be unsigned char * ?
    Can it be const char * ?

    I am new to C, sorry.
    See more | Go to post

    Leave a comment:


  • mjbauer95
    started a topic File reading
    in C

    File reading

    What is the best way to read a file in C?
    I have heard of using fread but then how do you find the size of the file?

    This is my example code but it seems to have odd errors.
    Code:
    char * read(char * filename){
    	FILE * fo;
    
    	fo = fopen(filename, "r");
    	if(fo){
    		char * buffer = NULL;
    		size_t result;
    		int length;
    		length = file_length(fo);
    		result = fread(buffer,1,length,fo);
    ...
    See more | Go to post

  • mjbauer95
    replied to Finding if a string is in a string in C
    in C
    Still having problems

    Now I am using strstr.
    But I still get a Segmentation Fault.

    My code is this:
    Code:
    #include <stdio.h>
    #include <string.h>
    
    int main(int argc, char **argv) {
    	int i;
    	char string[] = "123456789";
    	char variables[][1024] = {"7"};
    
    	for(i = (sizeof(variables) / 4) - 1; i > -1; --i) {
    		if (strstr(s
    ...
    See more | Go to post

    Leave a comment:


  • mjbauer95
    replied to Finding if a string is in a string in C
    in C
    OK.
    I didn't realize that strstr was a function, I can just use that.
    See more | Go to post

    Leave a comment:


  • mjbauer95
    started a topic Finding if a string is in a string in C
    in C

    Finding if a string is in a string in C

    I have a function that I want to be able to use to find out if a string is in a string.

    Code:
    int in(char string[], char finder[]){
    	int i = 0;
    	int j = 0;
    	int r = 0;
    	int flag = 0;
    
    	while (string[i] != '\0') {
    		if (flag==0){ // If a part of finder has not yet been found in string
    			if (string[i]==finder[0]){ // check if it is the first letter of finder is this string
    				flag=1;
    ...
    See more | Go to post
No activity results to display
Show More
Working...