Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to extract a number/byte from an array in C?
    primarykey
    data
    text
    <p>Here i have written a code which produces next 8 numbers from sequence.</p> <pre><code>int next_exp_data(unsigned long long int expected_data) { int i=0; unsigned long long int seq_gen_value=1976943448883713; unsigned long long int temp_data[10]; temp_data[0]=seq_gen_value; for(i=0;i&lt;10;i++) { printf("%llu",temp_data[i]); putchar('\n'); expected_data=temp_data[i]; temp_data[i+1]=temp_data[i] +2260630401189896; } return (expected_data); } </code></pre> <p>I want to know how can i extract each byte/number of the array and return each number/byte ??Please help me out.</p> <p>EDIT:Here's my code.Basically i want to read a file and compare the contents to check if the data read matches with generated sequential data.Here the buffer contains same data as temp_data is producing(ie 10 numbers like 0x07060504030201 next 0f0e0d0c0b0a0908 etc).I want to comapre buffer's data and the function's data.Can anyone suggest me how can i do.I am stuck.Any changes are appreciated.</p> <pre><code> #include&lt;stdio.h&gt; #include&lt;stdlib.h&gt; #include&lt;inttypes.h&gt; int main(void){ FILE *fp; char *buffer,c; size_t filesize,buffer_size; int i; unsigned long long int expected_data=1976943448883713; fp=fopen("seqdata.c","r"); if(fp==NULL){ fputs("Error\n",stderr); exit(1); } fseek(fp,0L,SEEK_END); filesize=ftell(fp); printf("Size of seqdata file is:%u \n",filesize); fseek(fp,0L,SEEK_SET); buffer=(char*)malloc(sizeof(char)*filesize); if(buffer == NULL){ fputs("\nMemory error ",stderr); } buffer_size=fread(buffer,sizeof(char),filesize,fp); for(i=0;i&lt;buffer_size;i++){ printf("%c",*(buffer +i)); } printf("No of elements read from file are:%u \n",buffer_size); fseek(fp,0L,SEEK_SET); int current_pos = 0; while(current_pos &lt; buffer_size){ if(*(buffer +current_pos) != expected_data) { fputs("Error\n",stderr); exit(1); } else{ printf("data matching \n"); current_pos++; expected_data=next_exp_data(expected_data); } } fclose(fp); free(buffer); return 0; } int next_exp_data(unsigned long long int expected_data) { int i=0; unsigned long long int seq_gen_value=1976943448883713; unsigned long long int temp_data[10]; temp_data[0]=seq_gen_value; for(i=0;i&lt;10;i++) { printf("%llu",temp_data[i]); putchar('\n'); expected_data=temp_data[i]; temp_data[i+1]=temp_data[i] +2260630401189896; } return (expected_data); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload