C结构休息 [英] C structure rest

查看:109
本文介绍了C结构休息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我希望得到你的帮助。基本上,我有一个结构在
我的c程序中,该结构用于逐行存储表的值

并进行一些处理。在一行处理结束时,

我想清除结构中每个成员的内容

,它们在处理下一行之前有不同的数据类型。这可以吗?
可以吗?请告诉我。


struct table_1

{

char col1 [4];

char col2 [7];

char col3 [7];

char col4 [4];

long dt_dt;

char temp1 [3];

char col5_i [2];

char col6_i [2];

char col7 [2] ;

char col5 [2];

};


非常感谢..


Dev-

Hi,

I am hoping to get some help from you. Basically, I have a structure in
my c program and the structure is used to store the values of a table
row by row and does some processing. At the end of one row processing,
I would like to clear the contents of each members of the structure
which has different data typebefore processing the next row. Can this
be done? Please let me know.

struct table_1
{
char col1[4] ;
char col2[7] ;
char col3[7] ;
char col4[4] ;
long dt_dt ;
char temp1[3] ;
char col5_i[2] ;
char col6_i[2] ;
char col7[2] ;
char col5[2] ;
} ;

Thanks a lot..

Dev-

推荐答案

de ****************** @ gmail.com 写道:
de******************@gmail.com wrote:




我希望得到你的帮助。基本上,我有一个结构在
我的c程序中,该结构用于逐行存储表的值

并进行一些处理。在一行处理结束时,

我想清除结构中每个成员的内容

,它们在处理下一行之前有不同的数据类型。这可以吗?
可以吗?请告诉我。


struct table_1

{

char col1 [4];

char col2 [7];

char col3 [7];

char col4 [4];

long dt_dt;

char temp1 [3];

char col5_i [2];

char col6_i [2];

char col7 [2] ;

char col5 [2];

};
Hi,

I am hoping to get some help from you. Basically, I have a structure in
my c program and the structure is used to store the values of a table
row by row and does some processing. At the end of one row processing,
I would like to clear the contents of each members of the structure
which has different data typebefore processing the next row. Can this
be done? Please let me know.

struct table_1
{
char col1[4] ;
char col2[7] ;
char col3[7] ;
char col4[4] ;
long dt_dt ;
char temp1[3] ;
char col5_i[2] ;
char col6_i[2] ;
char col7[2] ;
char col5[2] ;
} ;



当然,你可以使用:


#include< string>

#include < cstddef>


模板< typename CharT,std :: size_t N>

void clear(CharT(& arg)[N]){

std :: char_traits< CharT> :: assign(arg,N,CharT());

}


然后再做


void clear(table_1& arg){

clear(arg.col1);

// ...

arg.dt_dt = 0;

// ...

}

最好


Kai-Uwe Bux

Sure, you can use:

#include <string>
#include <cstddef>

template < typename CharT, std::size_t N >
void clear ( CharT (&arg) [N] ) {
std::char_traits< CharT >::assign( arg, N, CharT() );
}

and then do

void clear ( table_1 & arg ) {
clear( arg.col1 );
// ...
arg.dt_dt = 0;
// ...
}
Best

Kai-Uwe Bux


Kai-Uwe Bux写道:
Kai-Uwe Bux wrote:

devaraj.takhellambam写道:
devaraj.takhellambam wrote:


> my c program ...
>my c program...


模板< typename CharT,std :: size_t N>
template < typename CharT, std::size_t N >



你是一个残酷的人,Kai-Uwe。当低级别C问题时,不要用高级C ++诱惑devaraj




devaraj,你应该把这个问题发布到新闻:comp.lang.c,他们会在哪里
可能会建议如何安全地使用memset()。但是,您还询问

如何清除结构中每个成员的内容,这些成员在处理下一行之前具有不同的

数据类型。这是你和你的

数据库之间的关系,因此可能没有通用的C解决方案。


-

Phlip
http://www.greencheese.us/ZeekLand < - 不是博客!!!

You are kind''a cruel, Kai-Uwe. Don''t tempt devaraj with high-level C++
things when low-level C is the issue.

devaraj, you should post this question to news:comp.lang.c , where they will
probably recommend how to use memset() safely. However, you also asked how
to "clear the contents of each members of the structure which has different
data typebefore processing the next row." That''s between you and your
database, so there might not be a generic C solution.

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!


Kai-Uwe Bux写道:
Kai-Uwe Bux wrote:
德****************** @ gmail.com 写道:
de******************@gmail.com wrote:

>

我希望得到你的帮助。基本上,我在我的c程序中有一个结构,结构用于逐行存储表的值并进行一些处理。在一行处理结束时,我想在处理下一行之前清除结构中每个成员的内容,这些成员具有不同的数据类型。这可以吗?请告诉我。

struct table_1
{char col1 [4];
char col2 [7];
char col3 [7];
char col4 [4];
long dt_dt;
char temp1 [3];
char col5_i [2];
char col6_i [2];
char col7 [2];
char col5 [2];
};
>Hi,

I am hoping to get some help from you. Basically, I have a structure in
my c program and the structure is used to store the values of a table
row by row and does some processing. At the end of one row processing,
I would like to clear the contents of each members of the structure
which has different data typebefore processing the next row. Can this
be done? Please let me know.

struct table_1
{
char col1[4] ;
char col2[7] ;
char col3[7] ;
char col4[4] ;
long dt_dt ;
char temp1[3] ;
char col5_i[2] ;
char col6_i[2] ;
char col7[2] ;
char col5[2] ;
} ;



[剪掉一些令人难以置信的错综复杂的东西]


嗯,这是另一种尝试:


t = table_1();


如:

struct table_1 {

char col1 [ 4];

char col2 [7];

char col3 [7];

char col4 [4];

long dt_dt;

char temp1 [3];

char col5_i [2];

char col6_i [2];

char col7 [2];

char col5 [2];

};

#include< iostream>


int main(无效){

table_1 t;

t.dt_dt = 1;

t.col1 [0] =''a'';

std :: cout<< t.col1 [0]<< " " << t.dt_dt<< ''\ n'';

t = table_1();

std :: cout<< t.col1 [0]<< " " << t.dt_dt<< ''\ n'';

}

最好


Kai-Uwe Bux

[snip some incredibly convoluted stuff]

Well, here is another try:

t = table_1();

as in:
struct table_1 {
char col1[4] ;
char col2[7] ;
char col3[7] ;
char col4[4] ;
long dt_dt ;
char temp1[3] ;
char col5_i[2] ;
char col6_i[2] ;
char col7[2] ;
char col5[2] ;
};
#include<iostream>

int main ( void ) {
table_1 t;
t.dt_dt = 1;
t.col1[0] = ''a'';
std::cout << t.col1[0] << " " << t.dt_dt << ''\n'';
t = table_1();
std::cout << t.col1[0] << " " << t.dt_dt << ''\n'';
}
Best

Kai-Uwe Bux


这篇关于C结构休息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆