Extracting bytes from a byte array one by one (C) [closed] - c

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I have a byte array (dB). I am trying to extract the bytes one by one. Why isn't this code working? Any pointers? Logically am I wrong? Or something wrong with my implementation?

You have byte buffers declared like this:
unsigned char *decodeBuf;
To read a single value from that buffer, at offset i you simply write:
unsigned char b = decodeBuf[i];

try
int main()
{
unsigned char tmp;
tmp = getByte(dB+dOffset); dOffset++;
}
it should work

Related

How to convert a string containing a hex character code to the character value? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have an array of chars "0x55".
What I want to do is convert it to a char which is going to be U (because ASCII 0x55 = U).
So how to do this conversion?
#include <windows.h>
int main()
{
array[] = "0x55"
char test;
**// I want to move the string to that test to be one character which is U**
}
Any suggestions?
I think this is what you are after:
int main(int argc,char**argv)
{
char array[] = "0x55";
int value;
char test;
sscanf(array,"%x",&value);
test = value;
return 0;
}
In C++, I would code it a little differently, but this seems more like a C question.

What does the variable stores when it is assigned a printf statement in C [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
void main(){
int i;
i=printf("how r u?\n");
i=printf("%d",i);
printf("%d",i);}
The above code gives the result as:
how r u?
91
My question:
How does stores 9 and 1??
From the man page: Upon successful return, these functions return the number of characters printed.... If an output error is encountered, a negative value is returned.
So you are getting 9 and i because printf wrote out 9 and 1 characters respectively.
This is also relevant: Why does printf return a value?

what is the output of this code and how? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Program to understand sizeof operator:
#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
char *mess[]={ //array of pointers
"amol is a good boy",
"robin singh",
"genious boy",
"bitch please"
};
printf("%d",sizeof(mess)); // what does sizeof operator do?
}
Please explain the output of this code.
It is the storage size in bytes of 4 pointers to char.
You have your answer right in your question. It has a size of an array of pointers.
So the size is 4 * size of a pointer. (which is 32 on my system.) Your system might vary.

Error Handling in C? How to deal with scanf and illegal characters? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I'm writing a program in C, and for error handling it tells you to look for an illegal character when you're scanf-ing. In other words, look for a character that isn't an integer.
It is supposed to display an appropriate error message and terminate the program.
I'm a little confused as to how I go about looking for that illegal character, or noticing that it isn't an integer. Any help?
scanf() returns the number of successful arguments. If you do:
int ivar, return_val;
return_val = scanf("%i", &ivar);
return_val should be 1, cause of 1 parameter (ivar). Check the user input:
if (return_val == 1) {
// right input
} else {
// wrong input
}

Shortest C code to reverse a string [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 12 years ago.
Not counting the function signature (just the body) can anybody produce C code shorter than this function that will reverse a string and return the result as a pointer to the reversed string.. (not using a string reverse library function either)?
char * reverse_str(char * s)
{
char c,*f=s,*p=s;while(*p)p++;while(--p>s){c=*p;*p=*s;*s++=c;}return f;
}
not much longer, but it works.
#include <string.h>
/* precondition: s!=const && s!=NULL && *s!='\0' */
char *mystrrev(char *s)
{
char *a=s,*e=s+strlen(s)-1;
while( a<e )
{
char c=*a;
*a++=*e;
*e--=c;
}
return s;
}

Resources