Page 3 of 5 FirstFirst 12345 LastLast
Results 21 to 30 of 47

Thread: C Challenge (Part 1)

  1. #21
    Join Date
    Sep 2004
    Posts
    1,905
    Rep Power
    21

    Default

    C# cant be used to write doom 3
    Remember there is only so much ground work ASM, after that it is high level function calls. If you had an engine you would use the high level calls mostly C# and do not worry about overheads.

    @TJRAK, it the solution a mathematical equation eg max = sqnum1 - sqnum2? Or is it a speed optimiation that has to be used?
    Let's act on what we agree on now, and argue later on what we don't.
    Black men leave Barbeque alone if Barbeque don't trouble you

  2. #22
    Join Date
    Dec 2004
    Posts
    1,181
    Rep Power
    0

    Thumbs up @ Nigelt

    Quote Originally Posted by nigelt
    Code:
    #include <stdio.h>
    #include <ctype.h>
    
    
    void main(){
    	
      int i=0,x=0,loop=0;
      char pwd[6];
      do{
    	printf("Enter your five letter password:");
    	gets(pwd);
    	
    	for(x=0;x<5;x++){
    
            	if( (pwd[x] > 96 && pwd[x] < 123) || (pwd[x] > 64 && pwd[x]< 91)){
    			loop=1;
    			pwd[x] = tolower(pwd[x]); //converts letter to lowercase
    			
    			if(pwd[i]==122) //if the char is z
    				pwd[i]=97; //char is a
    			else pwd[i]+=1; //else increment by one 
    				
    				
    			if((pwd[i]-5) < 97) //if char is less than 5 chars away from a
    				pwd[i] = 122 - ((pwd[i]+1)-96); //calculate new value
    			else pwd[i]-=5; //else decrement by 5
    				
    				
    			if((pwd[i]+10) > 122) //if char is less than 10 chars away from z
    				pwd[i] =  97 + (10-(122 - (pwd[i]-1))); //calculate new value
    			else pwd[i]+=10; //else increment by 10
    				
    			i++;
    		}
    		else{
    			printf("Invalid character entered\n");
    			loop=0;
    			break;
    		}
    
    	}
      }while(loop==0);
    
    }

    Hey, i tried running this in Borland 5.02 and it did not run properly. Please reply and tell me which compiler you used. I even put in #include <conio.h> and added the getch(); right before the last brace and it still didn't do what it is supposed to do. I read through your code though and for the most part it seems that you knew the trick to solving the problem(Using the ASCI values of the letters of the password).
    For that i give you a thumbs up, but try running over your code and see if you got the same output when you enter the password "apple" as i had posted. Also, i did not specify that the password must be five letters MAX, so there is where a bit of challenge comes in.(Hint: To make things easier, try using the getc(stdin); function within the body of your loop to perform the necessary conversions one character at a time. The getc(stdin); function also returns an integer value because it converts the inputed character into an integer). Good Luck bredren.

    I am posting my solution nextweek, just studying for my exams now.
    Last edited by psybuck2002us; Apr 23, 2005 at 02:52 PM.

  3. #23
    Join Date
    Dec 2004
    Posts
    1,181
    Rep Power
    0

    Angry Grrrrr

    Quote Originally Posted by pogi_2nr
    what the?
    How about a real challenge?
    Since there is no challenge, how come i haven't seen you uploaded your source code? And dont come with the BS that it's a waste of your time to even attempt it because of your superior programming intellect.
    You starting to remind me of Campion College and the reason why they never entered School's Challenge Quiz.

  4. #24
    Join Date
    Oct 2004
    Posts
    4,814
    Rep Power
    24

    Default

    why waste ur time if its no challenge?

  5. #25
    Join Date
    Dec 2004
    Posts
    1,181
    Rep Power
    0

    Default

    And for all of you who think this is a homework, you are dead wrong. It's just that the C/C++ part of the forums is kinda boring and i was looking for a means of spicing things up while sharing ideas with other C programmers on solving problems. Thats why there is a "Part 1" in the title of my first post.

  6. #26
    Join Date
    Dec 2004
    Posts
    1,181
    Rep Power
    0

    Default

    Quote Originally Posted by leoandru
    why waste ur time if its no challenge?
    The challenge is there are numerous ways of approaching this problem. As i stated before, i wanted to see who could solve the problem in the most efficient way(least lines).

  7. #27
    Join Date
    Oct 2004
    Posts
    4,814
    Rep Power
    24

    Default

    Alright here is a challenge. Write a c/c++ program that will capture all the network packets from ur network interface and print the details on these packets.

    Details include:

    IPV version.
    Hearder Length
    Total Length of the packet
    Source address
    Destination address

    how is that for a challenge? Most ppl would say that this is simple.

  8. #28
    Join Date
    Dec 2004
    Posts
    1,181
    Rep Power
    0

    Default

    From your attitude, i can only assume that you are a bigshot programmer. So instead of wasting your time criticizing my challenges, why dont you make up your own challenges and solve them with your other programmer friends.
    My challenges are aimed towards all C programmers- from Beginners to Gods, so chill out. Zeen?

  9. #29
    Join Date
    Oct 2004
    Posts
    4,814
    Rep Power
    24

    Default

    Alright fine! i'll be looking out for your other challenges then.. peace!!

  10. #30
    Join Date
    Apr 2004
    Posts
    554
    Rep Power
    0

    Default

    Quote Originally Posted by psybuck2002us
    Hey, i tried running this in Borland 5.02 and it did not run properly. Please reply and tell me which compiler you used. I even put in #include <conio.h> and added the getch(); right before the last brace and it still didn't do what it is supposed to do. I read through your code though and for the most part it seems that you knew the trick to solving the problem(Using the ASCI values of the letters of the password).
    For that i give you a thumbs up, but try running over your code and see if you got the same output when you enter the password "apple" as i had posted. Also, i did not specify that the password must be five letters MAX, so there is where a bit of challenge comes in.(Hint: To make things easier, try using the getc(stdin); function within the body of your loop to perform the necessary conversions one character at a time. The getc(stdin); function also returns an integer value because it converts the inputed character into an integer). Good Luck bredren.

    I am posting my solution nextweek, just studying for my exams now.

    I used MSVC++ 6.0. I got the same output you did with apple. I only used 5 letters because the sample input you provided was 5 characters long. The code can be adjusted quite easily. Here's the code adjusted for passwords up to 99 characters.


    Code:
    #include <stdio.h>
    #include <ctype.h>
    #include <string.h>
    
    #define MAX 100
    
    void main(){
      unsigned int x=0;
      int i=0,loop=0;
      char pwd[MAX];
      do{
    	printf("Enter your password:");
    	gets(pwd);
    	
    	for(x=0;x<strlen(pwd);x++){
    
            	if( (pwd[x] > 96 && pwd[x] < 123) || (pwd[x] > 64 && pwd[x]< 91)){
    			loop=1;
    			pwd[x] = tolower(pwd[x]); //converts letter to lowercase
    			
    			if(pwd[i]==122) //if the char is z
    				pwd[i]=97; //char is a
    			else pwd[i]+=1; //else increment by one 
    				
    				
    			if((pwd[i]-5) < 97) //if char is less than 5 chars away from a
    				pwd[i] = 122 - ((pwd[i]+1)-96); //calculate new value
    			else pwd[i]-=5; //else decrement by 5
    				
    				
    			if((pwd[i]+10) > 122) //if char is less than 10 chars away from z
    				pwd[i] =  97 + (10-(122 - (pwd[i]-1))); //calculate new value
    			else pwd[i]+=10; //else increment by 10
    				
    			i++;
    		}
    		else{
    			printf("Invalid character entered\n");
    			loop=0;
    			break;
    		}
    
    	}
      }while(loop==0);
    	
    }
    I wouldn't use the getc() function because the for loop already traverses the array one char at a time.
    Last edited by nigelt; Apr 23, 2005 at 04:52 PM.
    Nexus S - Android 2.3.3 CM7, Jame Bond kernel with BLN, ext4 & full voodoo
    Bold 9700 - OS6.0.0.448

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •