473,385 Members | 1,492 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,385 software developers and data experts.

Help. Just getting started

I have a book Learn C in 21 days. But I'm using visual C++ as the
compiler.

Here is my code. What do I need to change to make it work with Visual
C++.

// list_it.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

void display_usage(void);

int line;

int _tmain(int argc, _TCHAR* argv[])
{
char buffer[256];
FILE *fp; <----(PROBLEM SEEMS TO BE HERE)

if( argc < 2)
{
display_usage();
exit(1);
}

/* if (( fp = fopen( argv[1], "r" )) == NULL )
{
fprintf( stderr, "Error opening file, %s!, argv[1] );
exit(1);
}
*/
line = 1;

while( fgets( buffer, 256, fp ) != NULL )
fprintf( stdout, "%4d:\t%s", line++, buffer );
fclose(fp);
return 0;
}

void display_usage(void)
{
fprintf(stderr, "\nProper Usage is: " );
fprintf(stderr, "\n\nLIST_IT filename.ext\n" );
}
Thanks,
Eric

Jul 23 '05 #1
8 1268
Eric wrote:
I have a book Learn C in 21 days.
C or C++? It matters, you know.
But I'm using visual C++ as the
compiler.

Here is my code. What do I need to change to make it work with Visual
C++.

// list_it.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

void display_usage(void);

int line;

int _tmain(int argc, _TCHAR* argv[])
{
char buffer[256];
FILE *fp; <----(PROBLEM SEEMS TO BE HERE)
'FILE' is a type defined in <stdio.h>. You need to include that header.
[...]


V
Jul 23 '05 #2
* Eric:
I have a book Learn C in 21 days.
There is more than one book with that title. One of them is
extremely bad. Probably that's the one you've got.

But I'm using visual C++ as the compiler.
Doesn't matter.

Here is my code. What do I need to change to make it work with Visual
C++.


Don't.

It will only suck you further down.

To get on track, see (blatant plug for my own tutorial)

<url: http://home.no.net/dubjai/win32cpptut/html/>

and get yourself a decent book, e.g. "Accelerated C++".

--
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?
Jul 23 '05 #3
ajk
On 1 Feb 2005 13:49:40 -0800, "Eric" <ri*****@yahoo.com> wrote:
I have a book Learn C in 21 days. But I'm using visual C++ as the
compiler.

Here is my code. What do I need to change to make it work with Visual
C++.

// list_it.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

void display_usage(void);

int line;

int _tmain(int argc, _TCHAR* argv[])
{
char buffer[256];
FILE *fp; <----(PROBLEM SEEMS TO BE HERE)

if( argc < 2)
{
display_usage();
exit(1);
}


missing

#include <stdio.h>

which isn't something vc++ specific, it is std c containing the
declaration of FILE among other things.

hth/ajk
--
"Those are my principles. If you don't like them I have others."
Groucho Marx.
Jul 23 '05 #4
Eric wrote:
I have a book Learn C in 21 days. But I'm using visual C++ as the
compiler.

That's nice. This is how I got started with C90.
Here is my code. What do I need to change to make it work with Visual
C++.

// list_it.cpp : Defines the entry point for the console application.
//

C files should be saved with .c extension. C++ files should be saved
with .cpp extension.
#include "stdafx.h"

Not standard C header. You should not create a new project in VC++, but
only a new source code file.
#include <stdio.h>

#include <stdlib.h>


void display_usage(void);

int line;

int _tmain(int argc, _TCHAR* argv[])

int main(int argc, char *argv[])
{
char buffer[256];
FILE *fp; <----(PROBLEM SEEMS TO BE HERE)

That one is OK.

if( argc < 2)
{
display_usage();
exit(1);

or better: return EXIT_FAILURE; (or exit(EXIT_FAILURE); but there is no
need to use EXIT() here).


--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #5
Thanks to everyone. My problem is solved. Thanks for the tutorial Alf
P. Steinbach. Here is what I ended up with. I program in Visual basic a
lot and trying to learn Visual C++. Thought I would learn C since I had
a book handy and climb the old ladder of knowledge.

Knowledge is power! and tons of responsibility

God Bless

#include "stdafx.h"
#include <stdio.h> <---Added this

void display_usage(void);

int line;

main(int argv, char *argc[]) <---changed the syntax of this
{
char buffer[256];
FILE *fp;

if( argv < 2)
{
display_usage();
exit(1);
}

if (( fp = fopen( argc[1], "r" )) == NULL )
{
fprintf( stderr, "Error opening file, %s!", argc[1] ); <---found a
missing quote(Stupied quotes)
exit(1);
}

line = 1;

while( fgets( buffer, 256, fp ) != NULL )
fprintf( stdout, "%4d:\t%s", line++, buffer );
fclose(fp);
return 0;
}

void display_usage(void)
{
fprintf(stderr, "\nProper Usage is: " );
fprintf(stderr, "\n\nLIST_IT filename.ext\n" );
}

Jul 23 '05 #6
Eric wrote:
Thanks to everyone. My problem is solved. Thanks for the tutorial Alf
P. Steinbach. Here is what I ended up with. I program in Visual basic a
lot and trying to learn Visual C++. Thought I would learn C since I had
a book handy and climb the old ladder of knowledge.

Since you are talking about C, and C and C++ are *different* languages
(although C++ retains most of ISO C 1990 standard as a subset), you had
better refer to comp.lang.c.


Knowledge is power! and tons of responsibility

God Bless

#include "stdafx.h"
#include <stdio.h> <---Added this

void display_usage(void);

int line;

main(int argv, char *argc[]) <---changed the syntax of this

int main(int argc, char *argv[])


--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #7
Eric wrote:
Thanks to everyone. My problem is solved. Thanks for the tutorial Alf
P. Steinbach. Here is what I ended up with. I program in Visual basic a
lot and trying to learn Visual C++. Thought I would learn C since I had
a book handy and climb the old ladder of knowledge.

Also learning C is not required to to learn C++, and in fact is not
recommended.
If you are interested in C++ try get a C++ book and learn it.
Check this page of mine:

http://www23.brinkster.com/noicys/learningcpp.htm
And these book reviews:

http://www.accu.org/bookreviews/publ...nner_s_c__.htm


--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #8
* Ioannis Vranos:

Also learning C is not required to to learn C++, and in fact is not
recommended.


If I might add to that:

it's so common a mistake to try to learn C first that this is a FAQ:

<url: http://www.parashift.com/c++-faq-lite/how-to-learn-cpp.html#faq-28.2>.

<quote>
[learning C] will not only waste your time, but it will teach you a bunch of
things that you'll explicitly have to un-learn when you finally get back on
track and learn OO/C++ (e.g., malloc(), printf(), unnecessary use of switch
statements, error-code exception handling, unnecessary use of #define
macros, etc.).
</quote>

--
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?
Jul 23 '05 #9

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

Similar topics

3
by: Y2KYZFR1 | last post by:
need some help getting started, it is just a "little" confusing on where to actually start. I want to write a turn based board game using Twisted as the networking layer. I just need a kind of...
0
by: Jim | last post by:
I need some help getting started with a .NET web project for a commercial site. I am new to .NET and my understanding of some (but not all) of its concepts is a little sparse. I apologize for the...
6
by: Jack Duijf | last post by:
Hello, I am looking for a person in The Netherlands that is willing to help me getting started with Vb.net. Please send a message to jack@aicn.nl if you can help me getting started with the...
15
by: Jay | last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send text messages to many, many employees via system.timer at a 5 second interval. Basically, I look in a SQL table (queue) to...
12
by: adamurbas | last post by:
ya so im pretty much a newb to this whole python thing... its pretty cool but i just started today and im already having trouble. i started to use a tutorial that i found somewhere and i followed...
1
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.