本文介绍了需要帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在全球宣布一个结构&有func1& main。

我将值赋给结构变量(这是一个指针)

fun1&想要在main中打印它。

这是同一类问题而不是实际代码。请帮助。

static struct des_rbuf {

unsigned int ind;

long long buf_adr;

unsigned int len ;

} desc_rbuf [512];


静态l;

int main()

{

fun1();

for(p = 0; p< l; p ++)

PRINT("%u \ t \t \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ .len);

//这里打印所有值0

}


fun1

{

desc_rbuf [l] .ind = i;

desc_rbuf [l] .buf_adr =(rxd-> buffer_addr& 0xFFFFFFFF);

desc_rbuf [l] .len = rxd-> length;

l ++;


//这里值desc_rbuf [l]正在打印

}

解决方案



请发布可编辑的代码。


PRINT()无法定义。

fun1 {是语法错误。

p无处声明。


无论如何,静态l;表示l等于0.

for(p = 0; p< l; p ++)

跳过该循环,因为0< 0是假的。


[责怪谷歌如果出现两次]




PRINT()无法定义。

fun1 {是语法错误。

p无处声明。


无论如何,静态l;表示l等于0.

for(p = 0; p< l; p ++)

跳过该循环,因为0< 0是假的。


[责怪谷歌如果出现两次]



这是一个相同的代码。 PRINT与printf()相同;我们

已经定义了宏。

问题不在编译中......

问题是main()中的PRINT,给出所有值为0每个

varible fo desc_tbuf [p] .everything

#include< stdio.h>

#include< stdlib.h>

#include" debug.h"

int n,m;

static int l = 0 ,z = 0,y = 0;


static struct tool_buf {

unsigned char * reg_name;

unsigned int reg_val;

unsigned char * reg_info;


} in_buf [100];


/ *用于Rx描述符信息* /

static struct des_rbuf {

unsigned int ind;

long long buf_adr;

unsigned int len;

} desc_rbuf [512];


/ *用于Tx描述符信息* /

static struct des_tbuf {

unsigned int ind;

long long buf_adr;

unsigned int len;

} desc_tbuf [512];

int main()

{

uint8_t r_type;

const char * filename =" data.txt";

uint32_t val,reg;

char buf [200],reg_type [20];

int i,j,k,o,p;

FILE * fp = fopen(filename," r");

int a,b,f,g;

char c,d,e,real_len [10];


if(fp)

{

for(i = 0; i< 5; i ++)

fgets(buf,sizeof(buf),fp);


while(fgets(buf,sizeof(buf),fp))

{

if(buf [17] ==''R''&& buf [18] ==''x'')

{

r_type = RX;

PRINT(" \ n \%s",buf);


for (j = 0; j
{

fgets(buf,sizeof(buf),fp);

PRINT( "%s",buf);

}


while(fgets(buf,sizeof(buf),fp))

{

if((buf [0] ==''c''&& buf [1] ==''u'')|| buf [0] ==' '\ n'')

继续;


sscanf(buf,"%3d :",& i);

if(i> = 0&& i< 512)

{

ns_nic_desc_info(r_type ,buf);

如果(i == 511)休息;

}

}

}


}


}

PRINT(" \ n \ nn \ n

=============================================== === =============================================== === ======================");

/ *注册信息* /

PRINT(\ nHere是错误的可能原因\ nn);

PRINT(" \ nReggisters Information");

PRINT(" ; \ n%32s \t\tValue(Hexa)\t\tDescription

\ n"," Field.Register_Name)");


for(n = 0; n< y; n ++)

{

PRINT(" \ n%35s\t\t0x %x \t\t\t%s",in_buf [n] .reg_name,

in_buf [n] .reg_val,in_buf [n] .reg_info);

}

打印(\ n \ n

\ n ============================================ ==== ============================================== ==== ================================");

/ *对于Rx响铃信息* /

PRINT(\ nDescriptors有关错误的信息RxRing \ n);

PRINT(" \ n \ nn \\ _ \\ n \\ n \\ n \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\
{

sprintf(real_len,"%d",desc_rbuf [p] .len);

PRINT(" \ n\t%你需要付出的代价是什么?b $ b%s",desc_rbuf [p] .ind,desc_rbuf [p] .buf_adr, real_len);

}


/ *表示Tx响铃信息* /

PRINT(&\\; \ n \ nDescriptors关于错误的信息TxRing \ n");

PRINT(" \\\ index \\\\\\\\\\\\\\\\\\\\\ />

for(p = 0; p< z; p ++)

{

//这是所有值为0

PRINT(&\\ t $ \\ t

%u",desc_tbuf [p] .ind,desc_tbuf [p] .buf_adr,desc_tbuf [p] .len);

}

返回;

}

void ns_nic_desc_info(uint8_t ring_type,char * buf)

{

int i,j,ac;

char * str1 =" 99999999";

ac = atoi(str1);


em_rx_desc_t rxd_inst;

em_rx_desc_t * rxd =& rxd_inst;

em_tx_desc_t txd_inst;

em_tx_desc_t * txd =& txd_inst;

开关(ring_type){

案例RX:

sscanf(buf,"%3d:@%8x%4d%2x%2x%4x" ;,& i,& rxd-> buffer_addr,& rxd-



/ *转储数据* /


PRINT(&\\;%3d ::%15s%8x" ;,i,缓冲地址:,(rxd-



PRINT(" \ n%15s \ t%d"," Length:",rxd-> length);

/ *状态描述* /

PRINT(" \ n%15s \ t0x%x"," Status:",rxd-> status);

PRINT(" \ n%20s \ t0x%x \ t%s"," DD(0)",(rxd-> status& 0x1)," DESCRIPTOR

DONE");

PRINT(" \ n%20s \ t0x%x \ t%s"," EOP(1)",( rxd-> status& 0x2),END OF

PACKET);

PRINT(" \ n%20s \ t0x%x \ t %s"," IXSM(2)",(rxd-> status& 0x4),IGNORE

CHECKSUM INDICATION);

PRINT(" ; \ n%20s \t0x%x \ t%s",VP(3),(rxd-> status& 0x8),PACKET IS

802.1 Q);

PRINT(" \ n%20s \ t0x%x \ t%s",TCPCS(5),(rxd-> status& 0x20 ),TCP

在支架上计算的支票号码&q uot;);

PRINT(" \ n%20s \ t0x%x \ t%s"," IPCS(6)",(rxd-> status& 0x40 ),IP

在PACLKET上计算的CHECKSUM);

PRINT(" \ n%20s \ t0x%x \ t%s"," ; PIF(7)",(rxd-> status& 0x80),PASSED IN-

精确过滤器);

/ *错误说明* /

PRINT(" \ n%15s \ t0%x"," Errors:",rxd-> errors);

PRINT(" \ n%20s \t0x%x \t%s",CE(0),(rxd-> errors& 0x1),CRC ERROR OR

ALIGNMENT ERROR);

PRINT(\ n%20s \ t0x%x \ t%s,SE(1),(rxd-> errors& 0x2 ),SYMBOL

ERROR);

PRINT(" \ n%20s \ t0x%x \ t%s"," SEQ(&# 2)",(rxd-> errors& 0x4),SEQUENCE

ERROR);

PRINT(" \ n%20s\t0x %x \t%s"," CXE RXV(4)",(rxd->错误s& 0x10),CARRIER

EXTENSION ERROR);

PRINT(" \ n%20s \ t0x%x \ t%s", TCPE(5),(rxd-> errors& 20),TCP / UDP

CHECKSUM ERROR);

PRINT(" \\ \\ n%20s \t0x%x \ t%s",IPE(6),(rxd-> errors& 40),IP CHECKSUM

ERROR) ;

PRINT(" \ n%20s \ t0x%x \ t%s"," RXE(7)",(rxd-> errors& 80)," ; RX DATA

ERROR");

/ *特别提交的说明* /

PRINT(" \ n%15s\t0x %x,Special:",rxd-> special);

PRINT(" \ n%20s \ t0x%x \ t%s"," VLAN (11:0)",(rxd-> special& 0xFFF)," VALN

IDENTIFIER");

PRINT(" \ n%20s \t0x%x \t%s"," CFI(12)",(rxd-



PRINT(" \ n%20s \ t0x%x \ t%s"," PRI(15:13)",(rxd - > special& 0xE000),USER

PRIORITY");

if(rxd-> status& 0x1)/ * dd是1 * /

{

if((rxd-> buffer_addr& 0xFFFFFFFF)== 0x0 ||(rxd-> length)== 0)

{

desc_rbuf [l] .ind = i;

desc_rbuf [l] .buf_adr =(rxd-> buffer_addr& 0xFFFFFFFF);

desc_rbuf [l] .len = rxd-> length;

l ++;


}


}


if(i == 511)

{

desc_rbuf [l] .ind = ac;

desc_rbuf [l] .buf_adr = 0;

desc_rbuf [l] .len = 0;

l ++;


}


休息;


案例TX:

休息;

}

}


有我们输入的日志文件

u可以为函数中的变量赋值ns_nic_desc_info&

尝试在main中打印。

其他任何其他符号或函数不是标准''C''是我们的宏

我们的宏

所以请忽略它。

i用指针试过也是但同样的问题,无论你怎么回事?
分配记忆:-(

尝试一下或者如果你知道

请帮助我。



我尝试过,通过在

的开头插入以下行你的程序:


#ifdef UNKNOWN

#include" debug.h"

#else

#define uint8_t

#define uint32_t

#define RX

#define PRINT(a,...)

#define em_rx_desc_t

#define em_tx_desc_t

#define ring_type

#define buf

#define TX

void ns_nic_desc_info(uint8_t, char *);

#endif


它没多大帮助。


如果你想要其他的话有人来帮助你,我们需要完整的COMPILABLE

代码。对于每个标识符,给我们代码定义

标识符,或者不使用它。你可能会认为你知道问题在哪里,并且它并不依赖于你没有给我们的东西。但是,你来找我们寻求帮助来解决你无法解决的问题。这意味着你不知道问题是什么,b $ b是什么意思,这意味着你无法确定问题出在哪里。唯一的

方式你可以确定你已经给了我们足够的信息,如果你给我们所有的信息。


hi
i m declaring a structure globally & there is func1 & main.
i m assigning the value to variable(this is a pointer) of structure in
fun1 & want to print it in main.
this is same kind of problem not the actual code. pls help.
static struct des_rbuf{
unsigned int ind;
long longbuf_adr;
unsigned int len;
}desc_rbuf[512];

static l;
int main()
{
fun1();
for(p=0;p<l;p++)
PRINT("%u\t\t\t\t%x\t\t\t
%u",desc_rbuf[p].ind,desc_rbuf[p].buf_adr,desc_rbuf[p].len);
//here it is printing all the values 0
}

fun1
{
desc_rbuf[l].ind=i;
desc_rbuf[l].buf_adr=(rxd->buffer_addr&0xFFFFFFFF);
desc_rbuf[l].len=rxd->length;
l++;

//here the value desc_rbuf[l] is printing right
}

解决方案

Please post compilable code.

PRINT() is nowhere defined.
fun1 { is a syntax error.
p is nowhere declared.

Regardless, static l; means l equals 0.
for(p = 0; p < l; p++)
That loop is skipped, because 0 < 0 is false.

[ blame google if this appears twice ]



PRINT() is nowhere defined.
fun1 { is a syntax error.
p is nowhere declared.

Regardless, static l; means l equals 0.
for(p = 0; p < l; p++)
That loop is skipped, because 0 < 0 is false.

[ blame google if this appears twice ]

well this was a same looking code. PRINT is same as printf(); that we
have defined in macro.
problem is not in compilation...
problem is that the PRINT in main(), giving all the values 0 for every
varible fo desc_tbuf[p].everything
#include <stdio.h>
#include <stdlib.h>
#include "debug.h"

int n,m;
static int l=0,z=0,y=0;

static struct tool_buf{
unsigned char *reg_name;
unsigned int reg_val;
unsigned char *reg_info;

}in_buf[100];

/*for Rx descriptor info*/
static struct des_rbuf{
unsigned int ind;
long longbuf_adr;
unsigned int len;
}desc_rbuf[512];

/*for Tx descriptor info*/
static struct des_tbuf{
unsigned int ind;
long long buf_adr;
unsigned int len;
}desc_tbuf[512];
int main()
{
uint8_t r_type;
const char *filename="data.txt";
uint32_t val,reg;
char buf[200],reg_type[20];
int i,j,k,o,p;
FILE *fp=fopen(filename,"r");
int a,b,f,g;
char c,d,e,real_len[10];

if(fp)
{
for(i=0;i<5;i++)
fgets(buf,sizeof(buf),fp);

while(fgets(buf,sizeof(buf),fp))
{
if(buf[17]==''R''&&buf[18]==''x'')
{
r_type=RX;
PRINT("\n\n%s",buf);

for(j=0;j<4;j++)
{
fgets(buf,sizeof(buf),fp);
PRINT("%s",buf);
}

while(fgets(buf,sizeof(buf),fp))
{
if((buf[0]==''c''&&buf[1]==''u'')||buf[0]==''\n'')
continue;

sscanf(buf,"%3d:",&i);
if(i>=0&&i<512)
{
ns_nic_desc_info(r_type,buf);
if(i==511) break;
}
}
}

}

}
PRINT("\n\n\n
================================================== ================================================== ======================");
/*Register information*/
PRINT("\nHere are The Probable Causes of Errors\n");
PRINT("\nRegisters Information");
PRINT("\n%32s\t\tValue(Hexa)\t\tDescription
\n","Field.Register_Name)");

for(n=0;n<y;n++)
{
PRINT("\n%35s\t\t0x%x\t\t\t%s",in_buf[n].reg_name,
in_buf[n].reg_val, in_buf[n].reg_info );
}
PRINT("\n\n
\n================================================ ================================================== ================================");
/*for Rx ring information*/
PRINT("\nDescriptors Information About Errors RxRing\n");
PRINT("\n\n\tindex Value\t\t\tBuffer Address\t\tLength");

for(p=0;p<l;p++)
{
sprintf(real_len,"%d",desc_rbuf[p].len);
PRINT("\n\t%u\t\t\t\t%x\t\t\t
%s",desc_rbuf[p].ind,desc_rbuf[p].buf_adr,real_len);
}

/*for Tx ring information*/
PRINT("\n\nDescriptors Information About Errors TxRing\n");
PRINT("\n\tindex Value\t\t\tBuffer Address\t\tLength");

for(p=0;p<z;p++)
{
//this is giving all values as 0
PRINT("\n\t%u\t\t\t\t%x\t\t\t
%u",desc_tbuf[p].ind,desc_tbuf[p].buf_adr,desc_tbuf[p].len);
}
return;
}
void ns_nic_desc_info(uint8_t ring_type,char *buf)
{
int i,j,ac;
char *str1="99999999";
ac= atoi(str1);

em_rx_desc_t rxd_inst;
em_rx_desc_t *rxd=&rxd_inst;
em_tx_desc_t txd_inst;
em_tx_desc_t *txd=&txd_inst;
switch(ring_type) {
case RX:
sscanf(buf,"%3d: @%8x %4d %2x %2x %4x",&i,&rxd->buffer_addr,&rxd-

/* dump the data */

PRINT("\n%3d:: %15s %8x",i,"Buffer Address:",(rxd-

PRINT("\n %15s\t%d","Length:",rxd->length);
/*status description*/
PRINT("\n %15s\t0x%x","Status:",rxd->status);
PRINT("\n%20s\t0x%x\t%s","DD(0)",(rxd->status&0x1),"DESCRIPTOR
DONE");
PRINT("\n%20s\t0x%x\t%s","EOP(1)",(rxd->status&0x2),"END OF
PACKET");
PRINT("\n%20s\t0x%x\t%s","IXSM(2)",(rxd->status&0x4),"IGNORE
CHECKSUM INDICATION");
PRINT("\n%20s\t0x%x\t%s","VP(3)",(rxd->status&0x8),"PACKET IS
802.1Q");
PRINT("\n%20s\t0x%x\t%s","TCPCS(5)",(rxd->status&0x20),"TCP
CHECKSUM CALCULATED ON PACKET");
PRINT("\n%20s\t0x%x\t%s","IPCS(6)",(rxd->status&0x40),"IP
CHECKSUM CALCULATED ON PACLKET");
PRINT("\n%20s\t0x%x\t%s","PIF(7)",(rxd->status&0x80),"PASSED IN-
EXACT FILTER");
/*Errors description*/
PRINT("\n%15s\t0%x","Errors:",rxd->errors);
PRINT("\n%20s\t0x%x\t%s","CE(0)",(rxd->errors&0x1),"CRC ERROR OR
ALIGNMENT ERROR");
PRINT("\n%20s\t0x%x\t%s","SE(1)",(rxd->errors&0x2),"SYMBOL
ERROR");
PRINT("\n%20s\t0x%x\t%s","SEQ(2)",(rxd->errors&0x4),"SEQUENCE
ERROR");
PRINT("\n%20s\t0x%x\t%s","CXE RXV(4)",(rxd->errors&0x10),"CARRIER
EXTENSION ERROR");
PRINT("\n%20s\t0x%x\t%s","TCPE(5)",(rxd->errors&20),"TCP/UDP
CHECKSUM ERROR");
PRINT("\n%20s\t0x%x\t%s","IPE(6)",(rxd->errors&40),"IP CHECKSUM
ERROR");
PRINT("\n%20s\t0x%x\t%s","RXE(7)",(rxd->errors&80),"RX DATA
ERROR");
/*Special filed description*/
PRINT("\n%15s\t0x%x","Special:",rxd->special);
PRINT("\n%20s\t0x%x\t%s","VLAN(11:0)",(rxd->special&0xFFF),"VALN
IDENTIFIER");
PRINT("\n%20s\t0x%x\t%s","CFI(12)",(rxd-

PRINT("\n%20s\t0x%x\t%s","PRI(15:13)",(rxd->special&0xE000),"USER
PRIORITY");
if(rxd->status&0x1)/*dd is 1*/
{
if((rxd->buffer_addr&0xFFFFFFFF)==0x0||(rxd->length)==0)
{
desc_rbuf[l].ind=i;
desc_rbuf[l].buf_adr=(rxd->buffer_addr&0xFFFFFFFF);
desc_rbuf[l].len=rxd->length;
l++;

}

}

if(i==511)
{
desc_rbuf[l].ind=ac;
desc_rbuf[l].buf_adr=0;
desc_rbuf[l].len=0;
l++;

}

break;

case TX:
break;
}
}


there is log file that we take input
u can assign value to the variables in the function ns_nic_desc_info &
try to print in main.
any other symbol or function that is not standard ''C'' that is d3efined
in our macros
so pls ignore it.
i tried with pointers also but again same problem, whereever u r
allocating the memoty :-(
try something or if u know
pls help me.


I tried that, by inserting the following lines at the beginning of
your program:

#ifdef UNKNOWN
#include "debug.h"
#else
#define uint8_t
#define uint32_t
#define RX
#define PRINT(a, ...)
#define em_rx_desc_t
#define em_tx_desc_t
#define ring_type
#define buf
#define TX
void ns_nic_desc_info(uint8_t, char *);
#endif

It didn''t help much.

If you want other people to help you, we need complete COMPILABLE
code. For each of those identifiers, give us code that either defines
the identifier, or doesn''t use it. You might think you know where
your problem is, and that it doesn''t depend upon the things you
haven''t given us. However, you came to us for help with a problem that
you couldn''t resolve. That means that you don''t know what the problem
is, which means that you can''t be sure where the problem is. The only
way you can be sure that you''ve given us enough information, is if you
give us ALL the information.


这篇关于需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 23:37