473,320 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

a C program

Hello
I am learning C++, a book exercise is asking to write a C program for
the purpose of learning compilation output when compile with c or c++
compiler. the program must use puts() without <stdio.h>.

is this a valid C program?

#include <iostream.h>

int main(){
puts("hello");
}
thanks
Aug 15 '05 #1
5 1493
Baloff wrote:
Hello
I am learning C++, a book exercise is asking to write a C program for
the purpose of learning compilation output when compile with c or c++
compiler. the program must use puts() without <stdio.h>.

is this a valid C program?

#include <iostream.h>

int main(){
puts("hello");
}


No, but this is:

#include <stdio.h>

int main(void)
{
puts("hello");
return 0;
}
August
Aug 15 '05 #2
On 15 Aug 2005 11:27:09 +1000, Baloff <wa****@wash.edu> wrote:
Hello
I am learning C++, a book exercise is asking to write a C program for
the purpose of learning compilation output when compile with c or c++
compiler. the program must use puts() without <stdio.h>.
That book exercise doesn't sound like it provides much benefit - at least
not at the stage mhere most beginner programmers are at. It also appears
your reference is slightly out of date, as the header files used are part
of an older standard.

In the current standard, such a program is trivial:

#include <cstdio>

using std::puts;

int main(void)
{
puts("hello");
return 0;
}

But that's another story. I'd suggest to switch books if you become too
confused.

is this a valid C program?

#include <iostream.h>
This would fail if it were a C program. <iostream.h> is a c++ header only.

Most likely, the book intends you to try compiling a "normal" program that
had it's <stdio.h> header removed. A pointless exercise, since omitting
such headers can result in undefined behaviour.

int main(){
puts("hello");
}


Aug 15 '05 #3
akarl <fu********@comhem.se> writes:
Baloff wrote:
Hello
I am learning C++, a book exercise is asking to write a C program for
the purpose of learning compilation output when compile with c or c++
compiler. the program must use puts() without <stdio.h>.
is this a valid C program?
#include <iostream.h>
int main(){
puts("hello");
}


No, but this is:

#include <stdio.h>

int main(void)
{
puts("hello");
return 0;
}
August


I have this exercise, now I am confused because I don't know what to
make out of its purpose.
In the Standard C library, the function puts( ) prints a char array to
the console (so you can say puts("hello")). Write a C program that
uses puts( ) but does not include <stdio.h> or otherwise declare the
function. Compile this program with your C compiler.
(Some C++ compilers are not distinct from their C compilers; in this
case you may need to discover a command-line flag that forces a C
compilation.) Now compile it with the C++ compiler and note the difference.

*********************main.c********************
//main.c
int main(void){
puts("hello");
return 0;
}
********************makefile********************
cproj: main.o
gcc -o $@ main.o

#did not work
#cproj2: main.o #another way of doing it
#insert <tab> here, g++ -x c -o $@ main.o

cppproj: main.o
g++ -Wall -o $@ main.o

clean:
rm -f *.o cp*

********************output********************
$ make clean
rm -f *.o cp*
$ make cppproj
cc -c -o main.o main.c
g++ -Wall -o cppproj main.o
$ ls
cppproj main.c main.o makefile
$ make cproj
gcc -o cproj main.o
$ ls
cppproj cproj main.c main.o makefile
$ ./cppproj
hello
$ ./cproj
hello

so it compiled all fine and ran ok, what the point?

thank you
Aug 15 '05 #4
* Baloff:

so it compiled all fine and ran ok, what the point?


If it did then that would be an important point, but it didn't: you didn't
do what the exercise asked, namely to compile as C++.

Checking date...

Huh? It's not september yet?

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Aug 15 '05 #5
I think the point of the exercise is to hand write the puts() declaration
then manually link it with the C Runtime Library...perhaps...

ben
Aug 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mike | last post by:
I am sure that I am making a simple boneheaded mistake and I would appreciate your help in spotting in. I have just installed apache_2.0.53-win32-x86-no_ssl.exe php-5.0.3-Win32.zip...
22
by: edgrsprj | last post by:
PROPOSED EARTHQUAKE FORECASTING COMPUTER PROGRAM DEVELOPMENT EFFORT Posted July 11, 2005 My main earthquake forecasting Web page is: http://www.freewebz.com/eq-forecasting/Data.html ...
0
by: Tom Lee | last post by:
Hi, I'm new to .NET 2003 compiler. When I tried to compile my program using DEBUG mode, I got the following errors in the C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7 \include\xdebug...
11
by: christopher diggins | last post by:
I am wondering if any can point me to any open-source library with program objects for C++ like there is in Java? I would like to be able to write things like MyProgram1 >> MyProgram2 >>...
1
by: Eric Whittaker | last post by:
hi all, im trying to write my first c++ program. a success, but i can't get the window to stay open after user enters input. it just automatically closes. right now the end of my program looks...
9
by: Hemal | last post by:
Hi All, I need to know the memory required by a c program. Is there any tool/utility which can give me the memory usage in terms of DATA segment, TEXT segment, BSS segment etc. I am working...
7
by: ibtc209 | last post by:
I just started programming in C, and I need some help with this problem. Your program will read the information about one MiniPoker hand, namely the rank and suit of the hand’s first card, and...
2
Banfa
by: Banfa | last post by:
Posted by Banfa The previous tutorial discussed what programming is, what we are trying to achieve, the answer being a list of instructions constituting a valid program. Now we will discuss how...
0
amitpatel66
by: amitpatel66 | last post by:
There is always a requirement that in Oracle Applications, the Concurrent Program need to be execute programatically based on certain conditions/validations: Concurrent programs can be executed...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.