473,734 Members | 2,375 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Little problem with a delirant program

#include <string.h>
#include <stdlib.h>
#include <stdio.h>
char *_(char *str1, char *str2)
{
char *res;
res = malloc((strlen( str1)+strlen(st r2))*sizeof(cha r));
strcpy(res, str1);
strcpy(res+strl en(str1), str2);
return res;
}

int main(void)
{
char a[] = "\nHey man look at me rockin' now\nI'm on the ";
char b[] = "Danny and Lisa";
char c[] = "\nThey take me away from";
char *d = _(_(a,"radio"), _(a,"video"));
char *e = _(d,_(" with ",b));
char *g = _("\nThe strangest places\nSweet ",b);
char *h = _(c,g);
char *i = _(_(h,c),_(h,c) );
char *j = _(e,i);
char *k = _(_(d,j),_(j,e) );
char *l = _(_(k,h),_(d,e) );
puts(++l); /* ++l gets rid of the spurious newline character at the
beginning */
return 0;
}

Why does this program add a spurious '1' after each occurrence of the last
line of the chorus? (i.e. "I'm on the video with Danny and Lisa1").
(I said it was delirant... But I fear that for copyright problems I won't be
able to sumbit a modification of this to the next IOCCC...)
T.I.A.

--
#include <stdio.h>
main()
{
printf("\n\n--\nArmy1987");
}
Mar 18 '07
14 1380
Army1987 wrote:
> Are you _sure_ you want to return before freeing all those arrays that
your (incorrectly) allocated?
Isn't my OS supposed to free them all immediately after main() returns?
There is nothing in C requiring your OS to do anything of the sort.
Whether your OS does so is, obviously, OS-dependent, and discussions of
that OS (or about the virtues of various OSs, as in Mr. McLean's post)
are completely off-topic here.
[...]
>>(I said it was delirant... But I fear that for copyright problems I won't
be
^^^^^^^^
What language is this a word in? And when did you say it? What
does it mean?

I meant "delirious" , sorry. I said it in the object line.
If something in your headers is somehow germane to your post, that
something belongs in the body of the post. Anyone who has used
newsgroups for more than ten minutes knows how worthless subject headers
are for anything substantive, including the subject of the post. Many,
perhaps most users of newsgroups use them at most to ignore threads that
they already know to be worthless.
Mar 19 '07 #11
Old Wolf wrote:
On Mar 19, 7:38 am, Eric Sosman <esos...@acm-dot-org.invalidwrot e:
>Army1987 wrote:
>>char *_(char *str1, char *str2)
Don't do that. Identifiers beginning with `_' are
reserved. There are a few contexts in which they are not
reserved, but this isn't one of them.

I thought such identifiers were only reserved if they started
with _ followed by an uppercase letter (or another _).
You have mixed up a couple different sets of identifiers
that are reserved in a couple different scopes. A few quiet
moments with the Standard might set your mind at rest.

--
Eric Sosman
es*****@acm-dot-org.invalid
Mar 19 '07 #12
>Isn't my OS supposed to free them all immediately after main() returns?
>
There is nothing in C requiring your OS to do anything of the sort.
Whether your OS does so is, obviously, OS-dependent, and discussions of
that OS (or about the virtues of various OSs, as in Mr. McLean's post) are
completely off-topic here.
[...]
<OT>
Of course not, but simply I can't see the reason why an OS should leave
memory allocated for a program which has already terminated, regardless of
what language it is written in.
</OT>
BTW, some implementation of free() do not give the memory back to the OS,
they just free it for new malloc()s, then if my OS is so cretinous and my
implementation of free() works this way (altho' anybody who's written such
an implementation for such an OS would be a complete idiot), freeing the
memory from within the program just before exiting would be no use. Anyway,
I do free memory allocated in a function other than main() before returning
if I know that it won't be needed by the caller.
>I meant "delirious" , sorry. I said it in the object line.

If something in your headers is somehow germane to your post, that
something belongs in the body of the post. Anyone who has used newsgroups
for more than ten minutes knows how worthless subject headers are for
anything substantive, including the subject of the post. Many, perhaps
most users of newsgroups use them at most to ignore threads that they
already know to be worthless.
Yes, but that was just a humorous comment...
Mar 19 '07 #13
Army1987 wrote:
> It wouldn't win. The IOCCC seeks obfuscations far more
original than just using an unusual name, especially an unusual
name that isn't yours to use.

I used that just because it was the shortest identifier which couldn't clash
with a letter (as I didn't know beforehand how many letters I had to use).
Of course I could just use a capital letter, but I didn't know about
reserved identifiers, and I thougth _ was cooler... ;-)
Of course, if I were really going to submit it to IOCCC, I'd brutally deface
it first... (I was just joking, I started learning C just about two months
ago... And I've seen some programs by the past winners of IOCCC and I really
think some of them really need to get a life...)
Hacking at the limits of a system, even to the point of making
unreadable programs, is a time-honoured way to express creativity and
really learn the system.

Would you say that someone learning to express themselves through prose
or poetry, "you need to get a life?" I'm guessing not, or not just
/because/ they were practicing the craft of writing, even if that
writing was opaque and stretched the rules of spelling and grammar to
their limits.

The IOCCC is even more of a challenge because you have to make prose
that is acceptable by a compiler and runtime environment.

You probably need a little more time on Dagobah before striking out on
your own to strike at the heart of the IOCCC.
Mar 19 '07 #14
Martin Ambuhl wrote:
Army1987 wrote:
.... snip ...
>
>I meant "delirious" , sorry. I said it in the object line.

If something in your headers is somehow germane to your post, that
something belongs in the body of the post. Anyone who has used
newsgroups for more than ten minutes knows how worthless subject
headers are for anything substantive, including the subject of the
post. Many, perhaps most users of newsgroups use them at most to
ignore threads that they already know to be worthless.
Such as this one.

--
<http://www.cs.auckland .ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfoc us.com/columnists/423>

"A man who is right every time is not likely to do very much."
-- Francis Crick, co-discover of DNA
"There is nothing more amazing than stupidity in action."
-- Thomas Matthews
--
Posted via a free Usenet account from http://www.teranews.com

Mar 20 '07 #15

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

Similar topics

3
3431
by: Ron Stephens | last post by:
I posted to my web site a fun little program called merlin.py today. Please keep in mind that I am a hobbyist and this is just a little hack, if you look at the code you will see that it is still possible to write spaghetti code, even with Python. I apologize, and I do intend to clean up the code, but it may take awhile. For now it works, with some bugs. It is a composite of a few scripts. The first, based on a script Max M uploaded to...
8
1951
by: Usman | last post by:
Huy everyone , Well I am not a big C++ programmer , I am just a little young kid on it tryint to learn . Actually I was given an assignment last week by my teacher which I solved completely but was unable to go through one question.
38
3349
by: Martin Marcher | last post by:
Hi, I've read several questions and often the answer was 'C knows nothing about .' So if C knows that little as some people say, what are the benefits, I mean do other languages know more or is it a benefit that C knows nearly nothing (what I can think about is that C is the largest common divisor defined on most available platforms)?
7
1531
by: selekta | last post by:
hi, i've recently started to deal a little bit with tcp/ip-socket-programming (linux). Now i've written a little test-program (as displayed further down). When i'm trying to compile it the gcc-compiler return "parse error in l.23/.24 before token '='. " the line before those two ( host_addr.sin_family = AF_INET;) is acepted without any problems. I'd be happy if anybody could tell me where's my fault.
0
1195
by: Kenneth Lantrip | last post by:
After some cleaning of some of my personal directories and files, I stumbled upon this little program I wrote some time ago. A scammer was trying to introduce me into his little pyramid scam. So to prove it was a bad idea, I decided to write this little program to find some confidence in the dicision to not get mixed up in his plot to rule the world. Anyway, Here is the program for your amusement. I only had to change a couple of...
54
2993
by: ash | last post by:
i am writing this program (for exercise1-9 in k&r-2nd edition) which removes extra spaces in string example- "test string" will be "test string" #include<stdio.h> #include<string.h> #include<conio.h> main() { char str,st;
102
5140
by: BoogieWithStu22 | last post by:
I am running into a problem with a web page I have created when viewing it in IE6 on some machines. The page has a database lookup. The user enters an account name or number and clicks a lookup button. This hits an AS400 database looks for matches and returns a dataset that is used to populate a datagrid. The user then selects one of the entries from the list, this entry is used to populate a couple of textboxes on the page and a couple...
23
7045
by: Niranjan | last post by:
I have this program : void main() { int i=1; if((*(char*)&i)==1) printf("The machine is little endian."); else printf("The machine is big endian."); }
8
9994
by: marknvicf | last post by:
I have read a bit about the endian differences, got a couple of jar/libs to help (Android and com.mindprod), but still am not sure how to fix this program that I have (written in JDK 1.4 by someone else who is not here anymore). I have some complicated structures in this program that I don't know how to fix. I have fixed DataInputStream and DataOutputStream but using com.mindprod and now have LEDataInput and Output Streams (Little Endian). The...
0
8946
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...
1
9236
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
9182
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
8186
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
6735
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
4550
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
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
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.