- #include "stdio.h"
-
-
-
char t[16] = {0x8F,0x78, 0xC6, 0x12, 0xBA,0x98, 0xA2,0x16, 0x8F,0x78, 0xC6, 0x12, 0xBA, 0x98, 0xA2, 0x16} ;
-
char w[44];
-
-
void main(){
-
-
for(int i=0 ; i<4 ; i++){
-
-
w[i] = (t[4*i], t[4*i+1], t[4*i+2], t[4*i+3]);
-
printf("%0x\t",w[i]);
-
-
}
-
}
i want to put some elements of the t array into the w array but when i do this, it prints only t[4*i+3]
i want the output to be something like this
w[0] = t[4*i], t[4*i+1], t[4*i+2], t[4*i+3] = 0x8F,0x78, 0xC6, 0x12
w[1] = 0xBA,0x98, 0xA2,0x16
and so on
2 1258 Banfa 9,065
Expert Mod 8TB
w[0] is a char, it can not have the value 0x8F,0x78, 0xC6, 0x12 which is 4 chars.
Did you mean to make w an array of arrays char w[11][4] ?
I suspect that (t[4*i], t[4*i+1], t[4*i+2], t[4*i+3]) is not doing what you think. The parenthesis do very little in this expression and I do not think you understand what the comma operator does.
The comma operator evaluates both it's expressions and returns the value of the right hand expression. it is left-to-right associative.
So in (t[4*i], t[4*i+1], t[4*i+2], t[4*i+3]) it evaluates t[4*i], t[4*i+1] returning the value of t[4*i+1], then it evaluates t[4*i+1], t[4*i+2] returning t[4*i+2] finally it evaluates t[4*i+2], t[4*i+3] returning t[4*i+3] for the whole expression hence w[0] has this value.
The comma operator is really not very useful and in 20+ years programming I have yet to use it in anger ever.
Additionally you have got the data type of t wrong. a char can hold a value in the range -128 - 127 but you are assigning it values in the range 0 - 255 you should probably be using unsigned char.
main should return int, not void.
To expand on what @Banfa said about char versus unsigned char, there are 3 different types: - char is used for characters, but should not be used for numbers. True, characters are encoded as integer values, but both the range of integral values supported and the character encoding vary between compilers. Don't ever fool yourself into thinking you know what they are.
- signed char is used for integers between -128 and +127.
- unsigned char is used for integers between 0 and 255.
Whenever a signed char or unsigned char variable appears on the right-hand side of an equals sign, its value is promoted to int. In many cases you might as well have used int from the start.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Matthias |
last post by:
Hi,
say I have a vector v1:
std::vector<SomeType> v1;
and I need a vector v2 of pointers to v1's elements:
std::vector<SomeType*> v2;
|
by: Bijoy Naick |
last post by:
I need to be able issue a query, then insert each record in the reader
into another table.
But, when I issue the myCommand.ExecuteNonQuery call, I get an error
telling me that a reader is...
|
by: Adam Hartshorne |
last post by:
Hi All,
I was wondering if somebody could tell me if there is an efficient way
to do the following. Say I have a list(or vector) A and a list B, I want
to remove any elements in B, that are also...
|
by: laredotornado |
last post by:
Hi,
Using PHP 4.4.4, I have this array
$my_arr = array("a", "b", "c", "d");
What is the easiest way to insert the element "|" between the elements
of the array so that the result is
...
|
by: JuiceyBananas |
last post by:
I have two tables a and b with columns in them, say a.test1 and b.test2, which are both ntext. I've done a lot of reading online about UPDATETEXT and WRITETEXT but I don't have enough experience to...
|
by: angel120 |
last post by:
So my second hw is to solve the 8 queens problem using a 1D array. The professor gave us a code that outputs the following (labeled as q):
0 2 5 7 6 3 1 4
The spaces 0-7 refer to the column #,...
|
by: Debajit Adhikary |
last post by:
I have two lists:
a =
b =
What I'd like to do is append all of the elements of b at the end of
a, so that a looks like:
a =
|
by: Simon Brooke |
last post by:
I have a document type which I'm developing and working with, which is
currently defined in a DTD, mainly because I still haven't really
learned to use schemas. In this document type I need to...
|
by: billelev |
last post by:
I have a large array of data (1000 x 40 x 3) that I am inserting into a database table. It is incredibly slow, and so I was wondering if there is a quicker way of inserting array data into a table....
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |