Thread: Can any one write a simple C Program 4 this??

  1. #16
    Registered User
    Join Date
    Dec 2007
    Posts
    12
    u mean i don't know da ligic behind the program,dont' b silly

  2. #17
    Registered User
    Join Date
    Dec 2007
    Posts
    12
    Do u hav win vista try it out,it works,works,works,worksworks

  3. #18
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    My Linux box is less impressed with your code.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #19
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Well, it seems like you are trying to make us believe you have done something REALLY impressive, when all you've done is write a simple DOS based program to write a single character to the screen. As I stated before, I did the same and much more in assembler in 1985, for both colour and monochrome display adapters [no, I'm not saying it's harder in assembler - just that I know what you're doing, and how your code works], 22 years ago. Judging from your writing style, that's probably 5-10 years before you were born.

    The code is definitely not able to "Run on any computer" - it ONLY works in 16-bit DOS or any other 16-bit PC environment. It definitely won't work on a Sparc-based SUN [without running it in a software based emulator], or in Windows on Alpha or Itanium [again, without using some sort of emulation code]. It also won't work in Linux, unless you load up the DOS emulator.

    So it seems like you believe this will run on any machine, but it definitely can't.

    So, I'm still curious as to if you actually understand what you are doing.
    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #20
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by sriki View Post
    Do u hav win vista try it out,it works,works,works,worksworks
    Does it work if you compile it with gcc, Visual Studio, Pelles C, DMC, or any other compiler produced in the last 5 years?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #21
    Registered User
    Join Date
    Aug 2006
    Posts
    100
    Interesting blog sriki, is there anything there at all that is original? or just a bunch of copywrite infringements?

  7. #22
    Registered User
    Join Date
    Dec 2007
    Posts
    12

    Thumbs down

    Hey man impressing if u wanna test my skill just write a program like dis
    Last edited by Salem; 12-03-2007 at 11:43 AM. Reason: Snip URL - read the rules, this isn't a site which tolerates "warez"

  8. #23
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    You don't need to make XP genuine. Simply don't buy your operating system from Russia. The dollar is so weak these days I am sure you could afford it. By the way, your link is dead.

    Stop trying to show off too. Everything you've showed us is really just duff code.

  9. #24
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I took your comment & blank line remover and tidiet it up, so that comments in strings aren't stripped [as they may be important].

    I also removed all the "Turbo C" stuff that is completely unnecessary - so now it will compile on most compilers with no problems.

    It also uses more safe fgets() instead of gets(). It's not completely safe against errors - if you enter a long string for input file, it will probably crash badly.

    Code:
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    
    int main()
    {
      FILE *inFile,*outFile;
      char fname[20];
      int ch;
      int quote = 0;
      int done = 0;
      int nlCount = 0;
      int inString = 0;
      int inComment = 0;
        
      printf("Enter the file name (.C or .TXT)\n");
      fgets(fname,sizeof(fname), stdin);
      *strchr(fname, '\n') = 0;
      inFile=fopen(fname,"r");
      if(inFile==NULL)
        {
          puts("Cannot open the source file!!!");
          exit(1);
        }
    
      outFile= fopen("target.c","w");
      if(outFile==NULL)
        {
          puts("Cannot create target file!!!");
          exit(1);
        }
      while(!done)
        {
          ch=fgetc(inFile);
          switch(ch) {
          case EOF:
    	done = 1;
    	continue;
          case '\n':
    	if (nlCount)
    	  continue;
    	nlCount ++;
    	break;
          case '/':
    	if (inString || inComment) 
    	  break;
    	if ((ch = fgetc(inFile)) == '*') 
    	  inComment = 1;
    	else 
    	  ungetc(ch, stdin);
    	break;
          case '*':
    	if (!inComment) 
    	  break;
    	if ((ch = fgetc(inFile)) == '/') 
    	  {
    	    inComment = 0;
    	    continue;
    	  }
    	else 
    	  ungetc(ch, stdin);
    	break;
          case '"':
          case '\'':
    	if (!inString) {
    	  quote = ch;
    	  inString = 1;
    	} else {
    	  if (quote == ch) 
    	    inString = 0;
    	}
    	break;
          case '\\':
            if (!inComment) 
    	  fputc(ch, outFile);
    	ch = fgetc(inFile);
    	
          default:
    	break;
          }
          if (!inComment) {
    	if (ch != '\n') 
    	  nlCount = 0;
    	fputc(ch, outFile);
          }
        }
      puts("DONE!! OP FILE IS \"TARGET.C\"\n");
      fclose(inFile);
      fclose(outFile);
      return 0;
    }
    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  10. #25
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by citizen View Post
    You don't need to make XP genuine. Simply don't buy your operating system from Russia. The dollar is so weak these days I am sure you could afford it. By the way, your link is dead.

    Stop trying to show off too. Everything you've showed us is really just duff code.
    Maybe the link is dead because sriki is not self-hosting, thus MS (or their lawyers) contact the hosting company and quietly requests that it should not be allowed...

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  11. #26
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    And he spake a parable unto them, Can the blind lead the blind? shall they not both fall into the ditch?

    Luke 6:39
    I think this is appropriate.

  12. #27
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by MacGyver View Post
    I think this is appropriate.
    Actually, I think the one you're looking for is something along the lines of "When arguing with a fool, others may not be able to tell who's the fool".

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  13. #28
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Quote Originally Posted by matsp View Post
    Actually, I think the one you're looking for is something along the lines of "When arguing with a fool, others may not be able to tell who's the fool".

    --
    Mats
    I think I missed that one.

    Answer not a fool according to his folly, lest thou also be like unto him.

    Answer a fool according to his folly, lest he be wise in his own conceit.


    ~ Proverbs 26:4-5
    Are you thinking of the first verse?

  14. #29
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    That's probably the proverb(s) that I paraphrased, yes. And don't you think that's more suitable?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  15. #30
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Perhaps, but I think we've been more than respectful to him.

    At the end of the day, the real issue is the poor newbies that don't know better and think his website is going to teach them to be 1337 h4x0rz that will be able to tear it up with their uber 1337 skillz.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 12-30-2007, 10:08 AM
  2. need a simple program
    By Peter Griffin in forum C++ Programming
    Replies: 7
    Last Post: 12-04-2005, 04:23 PM
  3. Need help with simple, simple program.
    By LightsOut06 in forum C Programming
    Replies: 5
    Last Post: 09-01-2005, 08:31 PM
  4. Problem with simple XOR program
    By spike_ in forum C++ Programming
    Replies: 8
    Last Post: 08-17-2005, 12:09 AM
  5. simple frontend program problem
    By gandalf_bar in forum Linux Programming
    Replies: 16
    Last Post: 04-22-2004, 06:33 AM