473,766 Members | 2,023 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
Roald Ribe wrote:
Yes but it is (was?) too limited for larger projects, unlike Java
and possibly C#.
But isn't that the whole point? That a learning language should be
simple? Because otherwise, there's really no reason not to start with
C++. If anything, it's less limited for large projects than Java or C#.
I disagree. In object oriented design and thinking everything is an
object.
But everything isn't an object. Or, if you make it one, all you'll get
is lots of extra complexity and a big loss of performance. Do you really
think every character and integer should be an object?
Expressions, flowcontrol and arrays is mostly the same in object oriented
and procedural laguages, just about everything else is different.
I believe it's very helpful to learn to walk before trying to run. Is
a Formula 1 racecar really the best vehicle for beginning drivers? Or
are they actually more likely to get hurt?
All the "object oriented cruft" (he he) is only that if your only goal
is efficiency in executables, and "real" programming is assembly.

While anything is doable in assembly, it's obviously not a good
language to develop in because the code is difficult to modify and
nonportable; besides, writing better assembly than a good compiler can
generate is hard.

But all that is besides the point. We're talking about languages
suitable for *learning* programming, not for developing large applications.
Michal

Jan 25 '06 #21
Roald Ribe wrote:
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 ;-)


I suppose you mean explicit pointers. I don't know a word about C#, but
in Java every variable, excepting those of primitive types, *is a
pointer*. It took me a while to realize it when they where teaching me
OOP in Java. Once I realized it, everything became obvious. That's what
I don't like about Java, it hides some things from you, and that's the
reason I've come to like C so much.
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).


Agreed.

<snip to EOF>

Jan 25 '06 #22
Antonio Contreras wrote:
I suppose you mean explicit pointers. I don't know a word about C#, but
in Java every variable, excepting those of primitive types, *is a
pointer*. It took me a while to realize it when they where teaching me
OOP in Java. Once I realized it, everything became obvious. That's what
I don't like about Java, it hides some things from you, and that's the
reason I've come to like C so much.


No they are not pointers, they are "handles to objects". You can
think of it as pointers if you like, but they are not the same.
Yes Java hides things from you (even what kind of CPU the program
is running on). That is why the programs are easier to make and
port from system to system. And the Java language is more percisely
defined, so the compiler can catch more errors.
I see Java and C as two different tools, each best for different
kinds of tasks.

Roald
Jan 28 '06 #23

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
9568
marktang
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...
0
10168
Oralloy
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...
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
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...
1
7381
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
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...
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.