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. 31 1998
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*
==============
"JAKE" <ja*****@yahoo. com> writes:
[snip] 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; }
That doesn't even compile. The declaration and definition of
assemble() are inconsistent, and you have a syntax error on the
sprintf() call. Also, I assume you mean "\n" rather than "/n".
Post your actual code (cut-and-paste, don't re-type). Otherwise we
have no way of guessing which errors are in your code and which ones
you introduced when you posted an approximation of it.
--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
JAKE wrote:
<snip> void assemble (float *a, int *b, char *c, char *all) {
sprintf(all,"%f , %d, %c" a, b, c);
Apart from what others have pointed out, you're missing a comma here.
That's why you get the third error.
sprintf(all,"%f , %d, %c", a, b, c);
^ return; }
Also, alloting only 6 bytes to `all` is sure to give you a buffer
overflow above. One way around it is to declare `all` with whatever
size you think you need, but ensure that `sprintf` can't give you a
larger string (also taking care about the terminating \0). E.g.:
char all[26];
sprintf(all, "%10f, %10d, %1c", a, b, c); /* single blanks */
--
BR, Vladimir
Keith Thompson <ks***@mib.or g> writes: "JAKE" <ja*****@yahoo. com> writes: [snip] here's what I have so far....
[snip] That doesn't even compile. The declaration and definition of assemble() are inconsistent, and you have a syntax error on the sprintf() call. Also, I assume you mean "\n" rather than "/n".
Post your actual code (cut-and-paste, don't re-type). Otherwise we have no way of guessing which errors are in your code and which ones you introduced when you posted an approximation of it.
Sorry, I didn't read the original message closely enough. I see that
you *did* post your actual code, and you were asking about the
compilation errors.
I think others have answered your questions.
--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
"Vladimir S. Oka" <no****@btopenw orld.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. . JAKE wrote:
<snip>
void assemble (float *a, int *b, char *c, char *all) {
sprintf(all,"%f , %d, %c" a, b, c);
Apart from what others have pointed out, you're missing a comma here. That's why you get the third error.
sprintf(all,"%f , %d, %c", a, b, c); ^
return; }
Also, alloting only 6 bytes to `all` is sure to give you a buffer overflow above. One way around it is to declare `all` with whatever size you think you need, but ensure that `sprintf` can't give you a larger string (also taking care about the terminating \0). E.g.:
char all[26];
sprintf(all, "%10f, %10d, %1c", a, b, c); /* single blanks */
Vladimir,
Are you using a fixed with font? FYI, the caret above is place under the %
of the %d in my newsreader...
RP
Rod Pemberton wrote: "Vladimir S. Oka" <no****@btopenw orld.com> wrote in message news:11******** **************@ z14g2000cwz.goo glegroups.com.. . JAKE wrote:
<snip>
void assemble (float *a, int *b, char *c, char *all) {
sprintf(all,"%f , %d, %c" a, b, c); Apart from what others have pointed out, you're missing a comma here. That's why you get the third error.
sprintf(all,"%f , %d, %c", a, b, c); ^
return; }
Also, alloting only 6 bytes to `all` is sure to give you a buffer overflow above. One way around it is to declare `all` with whatever size you think you need, but ensure that `sprintf` can't give you a larger string (also taking care about the terminating \0). E.g.:
char all[26];
sprintf(all, "%10f, %10d, %1c", a, b, c); /* single blanks */
Vladimir,
Are you using a fixed with font? FYI, the caret above is place under the % of the %d in my newsreader...
I'm forced to use blinkin' Google from the office. I tried my best with
Preview, but obviously failed. I now realise it'd have been better if I
just spelled it out: "missing comma after closing double quote". :-(
--
BR, Vladimir RP
Vladimir S. Oka wrote: Rod Pemberton wrote: "Vladimir S. Oka" <no****@btopenw orld.com> wrote in message news:11******** **************@ z14g2000cwz.goo glegroups.com.. . JAKE wrote:
<snip>
> void assemble (float *a, int *b, char *c, char *all) > { > > sprintf(all,"%f , %d, %c" a, b, c);
Apart from what others have pointed out, you're missing a comma here. That's why you get the third error.
sprintf(all,"%f , %d, %c", a, b, c); ^
> > return; > }
Also, alloting only 6 bytes to `all` is sure to give you a buffer overflow above. One way around it is to declare `all` with whatever size you think you need, but ensure that `sprintf` can't give you a larger string (also taking care about the terminating \0). E.g.:
char all[26];
sprintf(all, "%10f, %10d, %1c", a, b, c); /* single blanks */
Vladimir,
Are you using a fixed with font? FYI, the caret above is place under the % of the %d in my newsreader...
I'm forced to use blinkin' Google from the office. I tried my best with Preview, but obviously failed. I now realise it'd have been better if I just spelled it out: "missing comma after closing double quote". :-(
However, it looks OK viewed through Googgles (I'm using fixed-width
view, which seems to be utilising Courier New typeface). Could it be
/your/ font? ;-)
--
BR, Vladimir This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Matthew White |
last post by:
Hi,
I am assembling navigation links for an online article. The code works
fine for WIN IE 6 users, but not for NN4, or Mac IE5 users. When it
works, the resulting link looks like this:
http://www.mydomain.com/pr3/article2.php
On the machines with trouble, we get this:
|
by: Krakatioison |
last post by:
My sites navigation is like this:
http://www.newsbackup.com/index.php?n=000000000040900000
, depending on the variable "n" (which is always a number), it will take me
anywhere on the site... this number is always changing as I have hundreds of
thousand of pages of text on my site.
Problem:
- in my opinion this just not only look weird, but the variable "n" (number)
|
by: Stu Cazzo |
last post by:
I have the following:
String myStringArray;
String myString = "98 99 100";
I want to split up myString and put it into myStringArray.
If I use this:
myStringArray = myString.split(" ");
it will split myString up using the delimiter of 1 space
so that
|
by: John F Dutcher |
last post by:
I use code like the following to retrieve fields from a form:
recd =
recd.append(string.ljust(form.getfirst("lname",' '),15))
recd.append(string.ljust(form.getfirst("fname",' '),15))
etc., etc.
The intent is to finish by assigning the list to a string that I would
write to disk: recstr = string.join(recd,'')
|
by: Derek Hart |
last post by:
I wish to execute code from a string. The string will have a function name,
which will return a string:
Dim a as string
a = "MyFunctionName(param1, param2)"
I have seen a ton of people discuss how reflection does this, but I cannot
find the syntax to do this. I have tried several code example off of
gotdotnet and other articles. Can somebody please show me the code to do
this?
| |
by: Angus Leeming |
last post by:
Hello,
Could someone explain to me why the Standard conveners chose to typedef
std::string rather than derive it from std::basic_string<char, ...>?
The result of course is that it is effectively impossible to forward declare
std::string. (Yes I am aware that some libraries have a string_fwd.h header,
but this is not portable.)
That said, is there any real reason why I can't derive an otherwise empty
|
by: Kevin C |
last post by:
Quick Question:
StringBuilder is obviously more efficient dealing with string concatenations
than the old '+=' method... however, in dealing with relatively large string
concatenations (ie, 20-30k), what are the performance differences (if any
with something as trivial as this) between initializing a new instance of
StringBuilder with a specified capacity vs. initializing a new instance
without... (the final length is not fixed)
ie,
|
by: Andrew |
last post by:
I have written two classes : a String Class based on the book " C++ in
21 days " and a GenericIpClass listed below :
file GenericStringClass.h
// Generic String class
|
by: carl.manaster |
last post by:
Hi,
I'd like to take a string containing MSIL code, assemble it, execute
it, and receive the result all from my running C# application.
So far I've managed to manually create some MSIL code that I can
successfully assemble with ilasm and execute at the DOS prompt, and
I've read up on System.Reflection.Emit and CodeDom, but I don't see how
to do this. It looks like I would have to write a whole
System.CodeDom.Compiler.CodeCompiler; I...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |