여기 시퀀스에서 다음 8 개의 숫자를 생성하는 코드를 작성했습니다.C의 배열에서 숫자/바이트를 추출하는 방법은 무엇입니까?
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<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);
}
각 바이트/배열 번호를 추출하고 각 숫자/바이트를 어떻게 반환 할 수 있는지 알고 싶습니까? 제발 도와주세요.
편집 : 여기에 내 코드가 있습니다. 기본적으로 파일을 읽고 데이터가 생성 된 순차적 인 데이터와 일치하는지 확인하기 위해 내용을 비교합니다. 여기에 temp_data가 생성하는 것과 동일한 데이터가 버퍼에 들어 있습니다 (예 : 0x07060504030201과 같은 10 개의 숫자). 0f0e0d0c0b0a0908 등). 나는 버퍼의 데이터와 함수의 데이터를 비교해보고 싶다. 누구나 할 수있는 방법을 제안 해 줄 수있다. 나는 갇혀있다. 모든 변화는 인정된다.
#include<stdio.h>
#include<stdlib.h>
#include<inttypes.h>
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<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 < 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<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);
}
코드를 더 잘 포맷하면 도움이 될 것입니다. 모든 줄을 4 칸이나 탭으로 들여 쓰기 만하면됩니다. –
@ 클락 : 나는 들여 썼다. 나는 각 숫자를 가져 와서 문자별로 비교하고 싶다. – Unicorn
@Thej : 많은 코드를 게시했지만 원하는 것을 설명하는 코드는 두 줄뿐입니다. 나는 네가하고 싶은 것을 이해하지 못한다. 그리고 내가 유일한 사람이 아닌 것처럼 보인다. 프로그램이 무엇을해야하는지 명확하게 설명하면 더 나은 대답을 얻을 수 있습니다. – Gilles