组装一个字符串 [英] Assembling a string
问题描述
我对ansi c很新,而且我被卡住了我想在一个被调用的函数中组装一个字符串
。我需要发送三种不同的数据类型和
返回汇编的字符串。我一直在收到错误,例如...
28 C:\ Dev-Cpp \assemble.c''汇合'的冲突类型'
3 C:\ Dev-Cpp \assemble.c以前的''汇编''声明在这里
30 C:\ Dev-Cpp \assemble.c语法错误之前a
这是我到目前为止所拥有的......
#include< stdio.h>
void assemble(float,int,char,char []);
int main()
{
浮动a;
int b;
char c,全部[6];
printf(" ENTER A FLOATING POINT NUMBER:\ n");
scanf("%f",& a);
printf (/ nENTER A INTERGER:\ n);
scanf("%d",& b);
printf(" ; / nENTER A CHARACTER:\ n:");
scanf("%c",& c);
汇编(a ,b,c,全部);
put(全部);
返回0;
}
void assemble(float * a,int * b,char * c,char * all)
{
sprintf(全部,%f,%d,%c" a,b,c);
返回;
}
我应该转换数据类型在我将它们传递给
函数之前?
感谢任何帮助。
2006-02-23,JAKE< ja ***** @ yahoo.com>写道:我是ansi c的新手,我被卡住了我想在一个被调用的函数中组装一个字符串
。我需要发送三种不同的数据类型并返回已组装的字符串。我一直在收到错误,比如......
28 C:\Dev-Cpp \assemble.c''汇编'的冲突类型'
3 C:\ Dev-Cpp \assemble.c之前的''汇编''声明就在这里。
30 C:\ Dev-Cpp \assemble.c语法错误之前a
这就是我到目前为止所拥有的......
#include< stdio.h>
void汇编(float,int,char,char []) ;
int main()
{
浮动a;
int b;
char c,全部[6];
printf(" ENTER A FLOATING POINT NUMBER:\ n");
scanf("%f",& a);
printf(" / nENTER A INTERGER:\ n");
scanf("%d",& b);
printf(" / nENTER A CHARACTER:\ n:");
scanf("%c",& c);
汇编(a,b,c,all);
puts(all);
返回0;
}
void汇编(float * a,int * b,char * c,char * all)
{/>
sprintf(all,"%f,%d,%c" a,b,c);
返回;
我是否应该在将数据类型传递给
函数之前对其进行转换?
感谢任何帮助。
您已声明汇编以期望POINTERS到数据。而你
已经按值传递了数据。
没有给出解决方案:
int a; // a是一个整数
int * b; // b是一个整数的指针
b =& a; //将a的地址分配给b;
* b = 1; //将1放入指向b的地址中。在这种情况下,现在一个
== 1
-
删除evomer回复
JAKE写道:我对ansi c很新,而且我被困了我正试图组装一个在被调用函数中的字符串
。我需要发送三种不同的数据类型并返回已组装的字符串。我一直在收到错误,比如......
28 C:\Dev-Cpp \assemble.c''汇编'的冲突类型'
3 C:\ Dev-Cpp \assemble.c之前的''汇编''声明就在这里。
30 C:\ Dev-Cpp \assemble.c语法错误之前a
这是我到目前为止所拥有的......
.... void assemble(float,int,char,char []);
.... void assemble(float * a,int * b,char * c,char * all)
....
编译器抱怨前两行不相等
声明。
JAKE写道:我对ansi c很新,我被困住了,我正试图在一个被调用的函数中组装一个字符串
。我需要发送三种不同的数据类型
并返回组装好的字符串。我一直在收到错误,比如......
28 C:\Dev-Cpp \assemble.c''汇编'的冲突类型'
3 C:\ Dev-Cpp \assemble.c之前的''汇编''声明就在这里。
30 C:\ Dev-Cpp \assemble.c语法错误之前a
这就是我到目前为止所拥有的......
#include< stdio.h>
void汇编(float,int,char,char []) ;
int main()
{
浮动a;
int b;
char c,全部[6];
printf(" ENTER A FLOATING POINT NUMBER:\ n");
scanf("%f",& a);
printf(" / nENTER A INTERGER:\ n");
scanf("%d",& b);
printf(" / nENTER A CHARACTER:\ n:");
scanf("%c",& c);
汇编(a,b,c,all);
puts(all);
返回0;
}
void汇编(float * a,int * b,char * c, char * all)
{sprintf(全部,%f,%d,%c) a,b,c);
返回;
我是否应该在将数据类型传递给
函数之前对其进行转换?
感谢任何帮助。
更改
void assemble(float,int,char,char []) ;
要
void assemble(float *,int *,char *,char []);
>
或
void assemble(float *,int *,char *,char *);
更改
>
汇编(a,b,c,all);
汇总(& a,& b) ,& c,all);
或
汇编(& a,& b,& c,& all [0]);
-
==============
*不是学究者*
==============
I''m pretty new to ansi c and I''m stuck I''m trying to assemble a string
in a called function. I need to send it three different data types and
return the assembled string. I''ve been getting errors such as...
28 C:\Dev-Cpp\assemble.c conflicting types for ''assemble''
3 C:\Dev-Cpp\assemble.c previous declaration of ''assemble'' was here
30 C:\Dev-Cpp\assemble.c syntax error before "a"
here''s what I have so far....
#include <stdio.h>
void assemble(float, int, char, char[]);
int main()
{
float a;
int b;
char c, all[6];
printf("ENTER A FLOATING POINT NUMBER:\n");
scanf("%f", &a);
printf("/nENTER A INTERGER:\n");
scanf("%d", &b);
printf("/nENTER A CHARACTER:\n:");
scanf("%c", &c);
assemble(a, b, c, all);
puts(all);
return 0;
}
void assemble (float *a, int *b, char *c, char *all)
{
sprintf(all,"%f, %d, %c" a, b, c);
return;
}
Am I supposed to convert the data types before I pass them to the
function?
Appreciate any help.
On 2006-02-23, JAKE <ja*****@yahoo.com> wrote:I''m pretty new to ansi c and I''m stuck I''m trying to assemble a string
in a called function. I need to send it three different data types and
return the assembled string. I''ve been getting errors such as...
28 C:\Dev-Cpp\assemble.c conflicting types for ''assemble''
3 C:\Dev-Cpp\assemble.c previous declaration of ''assemble'' was here
30 C:\Dev-Cpp\assemble.c syntax error before "a"
here''s what I have so far....
#include <stdio.h>
void assemble(float, int, char, char[]);
int main()
{
float a;
int b;
char c, all[6];
printf("ENTER A FLOATING POINT NUMBER:\n");
scanf("%f", &a);
printf("/nENTER A INTERGER:\n");
scanf("%d", &b);
printf("/nENTER A CHARACTER:\n:");
scanf("%c", &c);
assemble(a, b, c, all);
puts(all);
return 0;
}
void assemble (float *a, int *b, char *c, char *all)
{
sprintf(all,"%f, %d, %c" a, b, c);
return;
}
Am I supposed to convert the data types before I pass them to the
function?
Appreciate any help.
You have declared assemble to expect POINTERS to the data. Whereas you
have passed the data by value.
Without giving the solution:
int a; // a is an integer
int * b; //b is apointer to an integer
b = &a; // assign the address of a to b;
*b=1; // put 1 into the address pointed to be b. In this case, now a
== 1
--
Remove evomer to reply
JAKE wrote:I''m pretty new to ansi c and I''m stuck I''m trying to assemble a string
in a called function. I need to send it three different data types and
return the assembled string. I''ve been getting errors such as...
28 C:\Dev-Cpp\assemble.c conflicting types for ''assemble''
3 C:\Dev-Cpp\assemble.c previous declaration of ''assemble'' was here
30 C:\Dev-Cpp\assemble.c syntax error before "a"
here''s what I have so far.... .... void assemble(float, int, char, char[]); .... void assemble (float *a, int *b, char *c, char *all)
....
The compiler complains that the two previous lines are not equal
declarations.
JAKE wrote:I''m pretty new to ansi c and I''m stuck I''m trying to assemble a string
in a called function. I need to send it three different data types
and return the assembled string. I''ve been getting errors such as...
28 C:\Dev-Cpp\assemble.c conflicting types for ''assemble''
3 C:\Dev-Cpp\assemble.c previous declaration of ''assemble'' was here
30 C:\Dev-Cpp\assemble.c syntax error before "a"
here''s what I have so far....
#include <stdio.h>
void assemble(float, int, char, char[]);
int main()
{
float a;
int b;
char c, all[6];
printf("ENTER A FLOATING POINT NUMBER:\n");
scanf("%f", &a);
printf("/nENTER A INTERGER:\n");
scanf("%d", &b);
printf("/nENTER A CHARACTER:\n:");
scanf("%c", &c);
assemble(a, b, c, all);
puts(all);
return 0;
}
void assemble (float *a, int *b, char *c, char *all)
{
sprintf(all,"%f, %d, %c" a, b, c);
return;
}
Am I supposed to convert the data types before I pass them to the
function?
Appreciate any help.
Change
void assemble(float, int, char, char[]);
To
void assemble(float *, int *, char *, char[]);
or
void assemble(float *, int *, char *, char *);
Change
assemble(a, b, c, all);
To
assemble(&a, &b, &c, all);
Or
assemble(&a, &b, &c, &all[0]);
--
==============
*Not a pedant*
==============
这篇关于组装一个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!