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.
Feb 23 '06
31 2001
Chris Torek wrote: Ian Malone <ib***@cam.ac.u k> wrote:
It's more common practice to put the functions in reverse order (with main at the bottom if it's present, small helpers at the top). Mainly for this reason; you eliminate the need for the separate prototype.
I do not know about "more common", but it does indeed eliminate the need for most prototypes. It is also the kind of system-building that is often referred-to as "bottom-up": you write the bottom-level supporting functions first, and read and comprehend them. Then you use those to assemble medium-level constructs; you use those to assemble the complete program.
Ever since we stopped using line numbers in the editors this style
is totally independant of top-down vs bottom-up programming. Just
write the main function, with stubs above. Then elucidate the
stubs as convenient.
--
"If you want to post a followup via groups.google.c om, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell. org/google/>
Also see <http://www.safalra.com/special/googlegroupsrep ly/>
Ian Malone <ib***@cam.ac.u k> wrote: Final point to the OP in this regard: it seems to be pretty common that newcomers to C use function prototypes and put their functions in the order: main, function1, function2 ...
It's more common practice to put the functions in reverse order (with main at the bottom if it's present, small helpers at the top).
Says you. I want main() on top; I prefer to read it that way. main() is
the most important function. I want to read it first. When I then need
to know what a function called in main() does, I read on.
I find this the more logical way to read code. If I first encounter a
small function which, say, fimbricates a mingus, I may have no idea what
a mingus is used for, and why it's being fimbricates. If I first read
the high-level code which declares and uses menzies, I may not yet know
the details of fimbrication, but at least I'll have an overview; and if
I then want more detail, I'll read on and find the function which does
that job with a good idea of what it operates on, and why.
Mainly for this reason; you eliminate the need for the separate prototype.
Pah. I refuse to hamper my style, and make my code more awkward (for me)
to read, just because of a broken compiler or editor.
If you do need a separate prototype (for a header, because of interdependent functions or because you'll need to interleave unrelated functions otherwise), then cut and paste it.
This, though, is true. And a small effort.
Richard
Richard Bos wrote: Ian Malone <ib***@cam.ac.u k> wrote:
<snip a long discussion about relative altitude
of main vis other functions>
OTH, /I/ haven't seen a `main()` in almost five years now (c.l.c not
withstanding). When I did see it, it was out of pure curiosity (someone
claimed it really did exist, and I set out to see for myself).
More seriously, I believe that for any project large enough to expand
beyond a single file this point is moot, anyway, and I don't think
there are many these days that don't.
--
BR, Vladimir
Richard Bos wrote: Ian Malone <ib***@cam.ac.u k> wrote:
<snip a long discussion about relative altitude
of main vis other functions>
OTH, /I/ haven't seen a `main()` in almost five years now (c.l.c not
withstanding). When I did see it, it was out of pure curiosity (someone
claimed it really did exist, and I set out to see for myself).
More seriously, I believe that for any project large enough to expand
beyond a single file this point is moot, anyway, and I don't think
there are many these days that don't.
--
BR, Vladimir
"Vladimir S. Oka" <no****@btopenw orld.com> wrote: Richard Bos wrote: Ian Malone <ib***@cam.ac.u k> wrote: <snip a long discussion about relative altitude of main vis other functions>
OTH, /I/ haven't seen a `main()` in almost five years now (c.l.c not withstanding). When I did see it, it was out of pure curiosity (someone claimed it really did exist, and I set out to see for myself).
That's what you get when you program on large-scale half-ISO
free-standing implementations , AKA MS Windows compilers :-P.
More seriously, I believe that for any project large enough to expand beyond a single file this point is moot, anyway, and I don't think there are many these days that don't.
No, my point is the same for any file which contains one or more main[1]
functions which depend on others. In almost all cases, IMO, the most
high-level function(s) should be at the top of the file, and helper
functions should be underneath. Ideally, helper functions for a single
main function should be underneath it, and helper functions for all
high-level functions should be underneath them all.
Richard
[1] Not necessarily main()...
On 2006-02-24, Richard Bos <rl*@hoekstra-uitgeverij.nl> wrote: "Vladimir S. Oka" <no****@btopenw orld.com> wrote:
Richard Bos wrote: > Ian Malone <ib***@cam.ac.u k> wrote:
<snip a long discussion about relative altitude of main vis other functions>
OTH, /I/ haven't seen a `main()` in almost five years now (c.l.c not withstanding). When I did see it, it was out of pure curiosity (someone claimed it really did exist, and I set out to see for myself).
That's what you get when you program on large-scale half-ISO free-standing implementations , AKA MS Windows compilers :-P.
More seriously, I believe that for any project large enough to expand beyond a single file this point is moot, anyway, and I don't think there are many these days that don't.
No, my point is the same for any file which contains one or more main[1] functions which depend on others. In almost all cases, IMO, the most high-level function(s) should be at the top of the file, and helper functions should be underneath. Ideally, helper functions for a single main function should be underneath it, and helper functions for all high-level functions should be underneath them all.
Richard
[1] Not necessarily main()...
In general I would agree : it is nothing but common sense to have the
highest level at the the top for hardcopy reading. Having said that I
would use a debugger/tags/IDE to browse code, so the physical location
is not as important as it once was. It is almost certain that I
wouldnt have any functions in the same file as main anyway - project
IDEs and makefiles make keeping things in monolithic files redundant -
and reduces that new print out size when function X got fixed :) TO be
honest, I prefer helper functions at the top of anything that uses
them : seems to be a more logical progression but it could be more me
thinking in terms of old one pass compilers/assemblers and just being
a stick in the mud.
But when I print out those files, guess which function is at the
beginning of the folder? Yup. main() or its equivalent.
--
Remove evomer to reply
Richard Bos wrote: "Vladimir S. Oka" <no****@btopenw orld.com> wrote:
Richard Bos wrote: Ian Malone <ib***@cam.ac.u k> wrote:
<snip a long discussion about relative altitude of main vis other functions>
OTH, /I/ haven't seen a `main()` in almost five years now (c.l.c not withstanding). When I did see it, it was out of pure curiosity (someone claimed it really did exist, and I set out to see for myself).
That's what you get when you program on large-scale half-ISO free-standing implementations , AKA MS Windows compilers :-P.
It's mobile phone, actually (and not WinCE one, more like home grown).
I was mildly surprised to see a `main()` actually, as it's not really
required. ;-) More seriously, I believe that for any project large enough to expand beyond a single file this point is moot, anyway, and I don't think there are many these days that don't.
No, my point is the same for any file which contains one or more main[1] functions which depend on others. In almost all cases, IMO, the most high-level function(s) should be at the top of the file, and helper functions should be underneath. Ideally, helper functions for a single main function should be underneath it, and helper functions for all high-level functions should be underneath them all.
I agree with this. I also like to see a "main" first, only to be later
broken down into smaller tasks. I seemed to have clutched onto the
`main()` bit...
--
BR, Vladimir
Richard Bos wrote: "Vladimir S. Oka" <no****@btopenw orld.com> wrote:
Richard Bos wrote: Ian Malone <ib***@cam.ac.u k> wrote:
<snip a long discussion about relative altitude of main vis other functions>
OTH, /I/ haven't seen a `main()` in almost five years now (c.l.c not withstanding). When I did see it, it was out of pure curiosity (someone claimed it really did exist, and I set out to see for myself).
That's what you get when you program on large-scale half-ISO free-standing implementations , AKA MS Windows compilers :-P.
It's mobile phone, actually (and not WinCE one, more like home grown).
I was mildly surprised to see a `main()` actually, as it's not really
required. ;-) More seriously, I believe that for any project large enough to expand beyond a single file this point is moot, anyway, and I don't think there are many these days that don't.
No, my point is the same for any file which contains one or more main[1] functions which depend on others. In almost all cases, IMO, the most high-level function(s) should be at the top of the file, and helper functions should be underneath. Ideally, helper functions for a single main function should be underneath it, and helper functions for all high-level functions should be underneath them all.
I agree with this. I also like to see a "main" first, only to be later
broken down into smaller tasks. I seemed to have clutched onto the
`main()` bit...
--
BR, Vladimir
"Vladimir S. Oka" <no****@btopenw orld.com> wrote:
You are, BTW, double-posting. This may be Google playing silly-buggers
again.
Richard
Richard Bos wrote: "Vladimir S. Oka" <no****@btopenw orld.com> wrote:
You are, BTW, double-posting. This may be Google playing silly-buggers again.
Indeed it is (was, I'm back to KNode and happy as a puppy).
Generally, Mon to Fri UK office hours I'm posting using Google as my
company's IS "security" policy does not allow NNTP. It's /very/
annoying frankly... :-(
--
BR, Vladimir
You will gain money by speculation or lottery. 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: 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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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: 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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |