汇编(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 stringin a called function. I need to send it three different data types andreturn 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 here30 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 thefunction?Appreciate any help. 解决方案You have declared assemble to expect POINTERS to the data. Whereas youhave passed the data by value.Without giving the solution:int a; // a is an integerint * b; //b is apointer to an integerb = &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....The compiler complains that the two previous lines are not equaldeclarations.Changevoid assemble(float, int, char, char[]);Tovoid assemble(float *, int *, char *, char[]);orvoid assemble(float *, int *, char *, char *);Changeassemble(a, b, c, all);Toassemble(&a, &b, &c, all);Orassemble(&a, &b, &c, &all[0]);--==============*Not a pedant*============== 这篇关于组装一个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
06-17 14:27