GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #31  
Old 08-Nov-2004, 23:47
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,335
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Dave, your second solution pointed to one more solution for me -- and this is really lame. Of course the #define will work too:
CPP / C++ / C Code:
#include <stdio.h>
void printf(const char *s)
{
  puts("Welcome to My World of Computing");
}

int main()
{
  printf("My World of Computing");
  return 0;
}
The instruction didn't say you had to use the parameter...
__________________

During the election they said Obama could only be elected when pigs fly. Well, we currently have an epidemic of Swine Flu. Coincidence?
  #32  
Old 09-Nov-2004, 07:25
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Okay Walt. For that you win the booby prize. That is pretty bad... but still meets the requirements.
  #33  
Old 09-Nov-2004, 08:43
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,218
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by WaltP
Dave, your second solution pointed to one more solution for me -- and this is really lame. Of course the #define will work too:
CPP / C++ / C Code:
#include <stdio.h>
void printf(const char *s)
{
  puts("Welcome to My World of Computing");
}

i
The instruction didn't say you had to use the parameter...


I kind of like it. The only problem is that printf() has already been prototyped in <stdio.h>. GNU gcc complains (with a warning) but executes OK. Borland bcc32 and Microsoft Visual C++ report it as an error and won't compile.

In order for it to run on all standard c compilers, you should declare printf() with the same parameters as in <stdio.h> (as I did in my example). Of course, then you will be declaring that its type as int, and should return some value.

The thing I like about puzzles like this (I'm not always good at puzzles):

Once you get over the "it can't be done" frame of mind, many alternatives may come to you. My definition of Engineer is: "Problem Solver". Sometimes the hardest thing to overcome in solving a problem is your first impression that "it's impossible".

Regards,

Dave
  #34  
Old 09-Nov-2004, 08:49
Dr. Evil Dr. Evil is offline
Member
 
Join Date: Oct 2004
Location: Netherlands
Posts: 120
Dr. Evil will become famous soon enough
Dang, everyone else's solution makes mine look really, really lame. I just nested the int main() function within the real main(). Technically, I didn't change the given main() function at all, the compiler (well, gcc at least, I don't know about the others) just ignores it.

Thus, the most pathetic solution of all:

CPP / C++ / C Code:
#include <stdio.h>

int main()
{
  printf("Welcome to ");
  int main()
  {
    printf("My World of Computing");
    return 0;
  }
  printf("My World of Computing");
  return 0;
}
  #35  
Old 09-Nov-2004, 09:08
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,218
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by Dr. Evil
Dang, everyone else's solution makes mine look really, really lame. I just nested the int main() function within the real main(). Technically, I didn't change the given main() function at all, the compiler (well, gcc at least, I don't know about the others) just ignores it.

Thus, the most pathetic solution of all:

CPP / C++ / C Code:
#include <stdio.h>

int main()
{
  printf("Welcome to ");
  int main()
  {
    printf("My World of Computing");
    return 0;
  }
  printf("My World of Computing");
  return 0;
}


This is a true aberration. main() is a very special function. You are only allowed to have one in standard C. Also, nested functions are not allowed in standard C. I am shocked that gcc lets you do this (it does--- I tested it). However, I kind of like the way that your mind works --- go for the bizarre!

I think the rules should have included the requirements that the resulting program be totally compliant with C-language standards.

However, inspired by your effort, I gladly give you credit for inspiring this one, that does obey the rules and is unquestionably a valid program for all standard C compilers.


CPP / C++ / C Code:
#include <stdio.h>

/* here is the new stuff */
int main()
{
  printf("Welcome to My World of Computing");
  return 0;
}

/* The original, unchanged, program is between #if 0 and #endif */
#if 0
#include <stdio.h>
int main()
{
  printf("My World of Computing");
  return 0;
}
#endif

I use the #if 0 construct all of the time to comment out blocks of code that may include /* */ comments. (In standard C, /* */ comments can't be nested.)

Since the original program had no such comments, I could have just put "/*" before its first line and "*/" after its last line instead of using #if 0

Regards,

Dave
  #36  
Old 09-Nov-2004, 11:03
Dr. Evil Dr. Evil is offline
Member
 
Join Date: Oct 2004
Location: Netherlands
Posts: 120
Dr. Evil will become famous soon enough
Thank you for your insight, I can't believe I left out the possibility of using preprocessor macros, or comments for that matter...
 
 

Recent GIDBlogAccepted for Ph.D. program by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
help with coding expectation maximization needed. thanks edge C Programming Language 8 08-Nov-2005 06:00
Some small things Allowee GIDSearch™ 6 14-Jul-2004 02:40
This is a small snippet from a much larger piece. Tang_Quester Open Discussion Forum 1 19-Mar-2004 02:17
Free 1st month / Free setup / No credit card needed...Plans start at 4.95 LarryIsaac Web Hosting Advertisements & Offers 0 11-Oct-2003 15:03
Script needed for letting user input a few days of data for tracking and analysis. tradertt MySQL / PHP Forum 3 06-Mar-2003 03:54

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 23:29.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.