473,766 Members | 2,035 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

New to C: Getting Application error when running program

I am new to the C programming language but have been programming in
Cobol for over 10 years. When I compile the following code, it
compiles clean but I get an application error both under Windows XP and
Win2K.

#include <stdio.h>
#include <ctype.h>

char title[] = "Year End Report";

char work_buffer[51];

main()
{
strcpy(work_buf fer,title);
strncenter(work _buffer,50);
printf("%s\n",w ork_buffer);
strljust(work_b uffer);
printf("%s\n",w ork_buffer);
strrjust(work_b uffer);
printf("%s\n",w ork_buffer);
}

/* Left justify a string */
strljust(str)
char *str;
{
int len;

len = strlen(str);
while (isspace(str) != 0) {
memmove (str,str + 1,len);
str[len] = ' ';
}
}

/* Reverse a string */
strrev(str)
char *str;
{
char ch;
char *end;

end = str + strlen(str) - 1;

while (str < end) {
ch = *end;
*end-- = *str;
*str++ = ch;
}
}

/* Right justify a string */
strrjust(str)
char *str;
{
strrev(str);
strljust(str);
strrev(str);
}

/* Truncate to last non-white character */
strtrunc(str)
char *str;
{
char *end;

end = str + strlen(str) - 1;

while ((*str != 0) && (isspace (*end) != 0)) {
*end-- = 0;
}
}

/* Pad a string for len with spaces */
struntrunc(str, len)
char *str;
int len;
{
while (strlen (str) < len) {
strcat (str,' ');
}
}

/* Center a string */
strcenter(str)
char *str;
{
strncenter (str, strlen(str));
}

/* Center a string within width */
strncenter(str, width)
char *str;
int width;
{
int non_blank_len, padding;

strtrunc (str);
strrev (str);
strtrunc (str);
non_blank_len = strlen (str);

padding = (width - non_blank_len) / 2;

struntrunc (str,padding);
strrev (str);
struntrunc (str,width);
}

It seems to be blowing up in the struntrunc function, but I can't
understand why. I know that this program is trying to take a string,
center it, left justify it and right justify it.

Any ideas on how I can get this program to run?

I am using Open Watcom C/C++ 1.4 but I had the same problem when I
tried it with OW 1.3.

Thanks

Jan 17 '06
22 2334
Roberto Waltman wrote:
while (isspace(str) != 0) {


%%%%%% should be isspace(*str) - isspace expects a char, not a pointer
to one


Nice try, but still incorrect. isspace takes an int, not a char, and
that int has to hold the unsigned value of the character in question,
which means that has to become

while(isspace(( unsigned char) *str) !=0) {

Or, since the test !=0 is completely superfluous in C:

while(isspace(( unsigned char) *str)) {

To the OP: yes, you need to get a less braindead C textbook. For people
who already know programming in general, K&R2 would be my recommendation.
Jan 21 '06 #11
Mike Polinske wrote:
I am using a book called "Moving from Cobol to C" by Mo Budlong which
is from 1993. I didn't realize C had changed that much


C actually hasn't changed all that much since 1993 --- the problem with
that book is that it had already fallen several years behind its time
back when it came out. Adding 12 years didn't exactly help solve that
problem, obviously, but neither is it responsible for the bulk of it.
Jan 21 '06 #12
Hans-Bernhard Broeker <br*****@physik .rwth-aachen.de> writes:
Mike Polinske wrote:
I am using a book called "Moving from Cobol to C" by Mo Budlong which
is from 1993.

I didn't realize C had changed that much


C actually hasn't changed all that much since 1993 --- the problem
with that book is that it had already fallen several years behind its
time back when it came out. Adding 12 years didn't exactly help solve
that problem, obviously, but neither is it responsible for the bulk of
it.


To be fair, I think there were still a number of pre-ANSI compilers in
use back in 1993. Some ANSI compilers were available, but code using
prototypes wasn't really portable unless you used a tool like
ansi2knr.

--
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.
Jan 21 '06 #13
"Default User" <de***********@ yahoo.com> wrote in news:43a2stF1j1 kkaU1
@individual.net :
The C++ people tend to disagree with this. I would generally agree that
if you only want to learn C++, then start with it. I don't agree with
them that C is a handicap to learning C++, not if one chooses a proper
introductory book for that language.


As an instructor who teaches both C and C++ I concur with this. Some in the
C++ community feel that learning C teaches "bad habits" (due to C's
limitations) that one must work to unlearn in C++. There is some truth to
that. However many of the issues students have difficulty with in C (such
as pointers) must also be mastered when learning C++ anyway. Dealing with
those issues in a smaller language with fewer distracting and interacting
features is often easier than trying to learn them on top of everything
else in C++.

However, the argument I use in favor of learning C first and then C++ is
that by doing so you understand better where C leaves off and C++ begins.
That way when you are working in an environment that only offers C you have
a better idea of what you can (and can't) do. C and C++ are different
languages but they have an unusually intimate relationship. It is often
helpful, I believe, to have a clear idea about the boundary between them.

Peter
Jan 24 '06 #14
Peter C. Chapin wrote:
As an instructor who teaches both C and C++ I concur with this. Some in the
C++ community feel that learning C teaches "bad habits" (due to C's
limitations) that one must work to unlearn in C++. There is some truth to
that. However many of the issues students have difficulty with in C (such
as pointers) must also be mastered when learning C++ anyway. Dealing with
those issues in a smaller language with fewer distracting and interacting
features is often easier than trying to learn them on top of everything
else in C++.

Perhaps this will give people some idea of relative complexity of the
languages:

The ISO C90 standard had roughly 200 pages.

The ISO C99 standard has roughly 550; however, about 350 pages are
devoted solely to the library.

The ISO C++98 standard has roughly 770 pages, *however* it refers to
the ISO C standard for Standard C library description - otherwise it'd
be about 1,100 pages.

While this is not a good measure of complexity, it should be obvious
that with several times as many pages in the Standard, the language is
going to be significantly more complex.
Michal

Jan 24 '06 #15

My 2 cents worth:

It depends on how much and what type of development you are
going to do. I learned procedural languages first (basic,
pascal and c), that gave me serious disadvantages when
trying to think/learn object-oriented Java & others.
I do not think that either C or C++ are good learning
(first) languages. Go with Java or C# as a first language
since thar will be (IMO) much more productive (easy to learn),
and learn C/C++ later when/if the need arises.

Roald
Jan 24 '06 #16
Michal Necasek wrote:
Peter C. Chapin wrote:
As an instructor who teaches both C and C++ I concur with this.
Some in the C++ community feel that learning C teaches "bad habits"
(due to C's limitations) that one must work to unlearn in C++.
There is some truth to that. However many of the issues students
have difficulty with in C (such as pointers) must also be mastered
when learning C++ anyway. Dealing with those issues in a smaller
language with fewer distracting and interacting features is often
easier than trying to learn them on top of everything else in C++.


Perhaps this will give people some idea of relative complexity of
the languages:

The ISO C90 standard had roughly 200 pages.

The ISO C99 standard has roughly 550; however, about 350 pages are
devoted solely to the library.

The ISO C++98 standard has roughly 770 pages, *however* it refers
to the ISO C standard for Standard C library description -
otherwise it'd be about 1,100 pages.

While this is not a good measure of complexity, it should be
obvious that with several times as many pages in the Standard, the
language is going to be significantly more complex.


It is not just the complexity, but the organization of the
language. Extended Pascal (ISO10206) is roughly comparable to C99,
but the standard comprises about 230 pages. Pascal does not
contain the multiple reuses of symbols, nor the complex
precedences, etc. The library is much better organized, because it
was designed, rather than just grew.

--
"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/>
Jan 24 '06 #17
Michal Necasek wrote:
Roald Ribe wrote:

I do not think that either C or C++ are good learning
(first) languages. Go with Java or C# as a first language
since thar will be (IMO) much more productive (easy to learn),
and learn C/C++ later when/if the need arises.
I agree that C (let alone C++) is not easy for people who don't know
any programming. Heck, even experienced programmers sometimes have
trouble sorting out the finer points of pointer usage. However, I highly
doubt that Java and C# are any better.


Well, at least they do not have pointers ;-)
The first 'serious' programming
language I learned was Pascal, and in retrospect I can say that it was
an excellent language for learning (not surprising, as that's exactly
what it was designed for).
Yes but it is (was?) too limited for larger projects, unlike Java
and possibly C#. My point was also that if they will program in OO
languages in the future it is probably best to learn that way of
thinking about the peoblems and solutions right away.
What many people apparently fail to realize is that object-oriented
programming is largely a question of application design, not nuts and
bolts programming. To learn programming basics like variables, arrays,
structures, expressions, loops, subroutines, etc. etc., all the object
oriented cruft just gets in the way. In other words, both Java and C# as
a first language violate the KISS principle.
I disagree. In object oriented design and thinking everything is an
object. That some partially object oriented languages does not reflect
that (mostly for efficiency purposes) should not affect such a discussion.
Expressions, flowcontrol and arrays is mostly the same in object oriented
and procedural laguages, just about everything else is different.

All the "object oriented cruft" (he he) is only that if your only goal
is efficiency in executables, and "real" programming is assembly.
If the goal is correctness of the program in as short development
(or learning) cycle as possible, there is no doubt that Java and
others is better for that than C (using languages I know best
for comparison). Most programmers will never need to care about how
a character is represented in a RAM chip.
It is possible that a scripting language might be good for learning
protramming these days, although the typeless coding those languages
promote might give a beginner some very bad habits.


It all depends on what people are going to do. Not many percent of
the people who gets into programming will ever get a chance to make
a device driver or embedded sowtware or low level stuff like that.
Most will end up making software shuffling SQL data around in one
way or another. Who knows if we really need to learn more than a
scripting language for such a task?

Roald
Jan 25 '06 #18
Roald Ribe wrote:

I do not think that either C or C++ are good learning
(first) languages. Go with Java or C# as a first language
since thar will be (IMO) much more productive (easy to learn),
and learn C/C++ later when/if the need arises.

I agree that C (let alone C++) is not easy for people who don't know
any programming. Heck, even experienced programmers sometimes have
trouble sorting out the finer points of pointer usage. However, I highly
doubt that Java and C# are any better. The first 'serious' programming
language I learned was Pascal, and in retrospect I can say that it was
an excellent language for learning (not surprising, as that's exactly
what it was designed for).

What many people apparently fail to realize is that object-oriented
programming is largely a question of application design, not nuts and
bolts programming. To learn programming basics like variables, arrays,
structures, expressions, loops, subroutines, etc. etc., all the object
oriented cruft just gets in the way. In other words, both Java and C# as
a first language violate the KISS principle.

It is possible that a scripting language might be good for learning
protramming these days, although the typeless coding those languages
promote might give a beginner some very bad habits.
Michal

Jan 25 '06 #19
>It all depends on what people are going to do. Not many percent of
the people who gets into programming will ever get a chance to make
a device driver or embedded software or low level stuff like that.
Most will end up making software shuffling SQL data around in one
way or another. Who knows if we really need to learn more than a
scripting language for such a task?


This is probably true, but possibly sad. It is my claim in the embedded
world, that no one has any business playing there if they aren't capable of
reading a disassembly listing. It is the final word on: a) whether the code
is doing what you expected it to, and, b) whether it is doing it in an
efficient manner.

Obviously for a one-off query that will never be repeated, or an analysis of
an experiment, the effort isn't worth the trouble. The simplest (human)
path to a correct answer is the best one. But for production code (which
encompasses all of the embedded and most of the business market) efficiency
is a useful objective. I've seen so much garbage that is often 10 times a
compute intensive as what it would be if the programmer had had any concept
of how is code was being executed.

I will grant that OO takes a somewhat different mindset than C programming,
and it comes harder for some than others, and some may find it harder if
they start with procedural/sequential programming. On the other hand, for
me, the biggest insight came when I discovered that an object function call
in C++ passed a pointer to the object as the first (hidden) parameter.
Since I think along the lines of hardware, that gave me significant insight
into how OOs work, and thereby into how to use them (and use them
efficiently).

Wilton
Jan 25 '06 #20

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

Similar topics

0
1343
by: Oleg Medyanik | last post by:
Hello, All I have a question regarding running .NET application on W2k SP4 server in Terminal Service client, After we installed SP4 we face the exception when closing .NET app in Terminal Service Client After reading this http://support.microsoft.com/default.aspx?kbid=823485 we converted our apps to Framework 1.1 but it has no effect. And also i have a administrative
1
1324
by: Yoshitha | last post by:
hi i've vb application and i migrated it to vb.net application and it is working fine when i run this in windows 2000 professional where am having dotnetframwork 1.1 and visual studio 2003. but when i run the same application in XP home edition which is having only framwork 1.1 i am getting the following error.
8
10015
by: Rod | last post by:
I have been working with ASP.NET 1.1 for quite a while now. For some reason, opening some ASP.NET applications we wrote is producing the following error message: "The Web server reported the following error when attempting to create or open the Web project located at the following URL: 'http://localhost/WebApplication1'. 'HTTP/1.1 500 Internal Server Error'."
2
2116
by: David Hearn | last post by:
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. SQLExpress database file auto-creation error: The connection string specifies a local SQL Server Express instance using a...
12
5877
by: JohnR | last post by:
I have narrowed a problem down to a simple example. A form with two buttons. One EXIT and one FBD. The exit button does an "END" to end the application. The FBD button does a FolderBrowserDialog and nothing else. When I start the application and hit EXIT everything works fine. However if it display the FBD box (even if I don't pick a folder and immediately hit cancel) and then try to exit one of two things happens. Either (1) the...
2
4221
by: MSK | last post by:
Hi, Continued to my earlier post regaring "Breakpoints are not getting hit" , I have comeup with more input this time.. Kindly give me some idea. I am a newbie to .NET, recently I installed .NET. I could not debug using breakpoints, breakpoints are not getting hit, but the application is working fine with out any issue.
6
3623
by: David Lozzi | last post by:
Hello there, I'm getting the following error System.NullReferenceException: Object reference not set to an instance of an object. at shopping_bag.GetBagTotals()
0
2922
by: buntyindia | last post by:
Hi, I have a very strange problem with my application. I have developed it using Struts. I have a TextBox With Some fixed value in it and on Submit iam passing it to another page. <html:form action="/login"> <html:text property="userName" value="Bunty"/> <html:submit/>
4
5729
by: imaloner | last post by:
I am posting two threads because I have two different problems, but both have the same background information. Common Background Information: I am trying to rebuild code for a working, commercially sold application with only partial build instructions. The previous maintainer of the code (a mixture of C and C++) is no longer with the company, but when he built the code he used MSVC++, and though I am not certain of the version he was ...
0
10008
jinu1996
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...
1
9959
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,...
0
9837
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8833
agi2029
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...
0
6651
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();...
0
5279
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...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.