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
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>
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
|
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.
|
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'."
|
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...
|
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...
| |
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.
|
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()
|
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/>
|
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 ...
|
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: 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...
| |
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: 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...
|
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...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |