Solve the given C Puzzle

Status
Not open for further replies.

fun2sh

Pawned!... Beyond GODLIKE
wat do u mean by
adi007 said:
No pointers,functions,structures,unions......
then how will one store a string (as arrays are also pointers)
n which functions r not allowed??????????
 
OP
A

adi007

Youngling
QwertyManiac said:
Only 1 variable but constants are allowed as desired?
no constants...

fun2sh said:
wat do u mean by

then how will one store a string (as arrays are also pointers)
n which functions r not allowed??????????
arrays are not pointers..
There are the separate group of structured datatype..
 
Last edited:

fun2sh

Pawned!... Beyond GODLIKE
yeah they r seperate group of data structures but they too are based on pointers, so tel me can we use them or not.??
 
OP
A

adi007

Youngling
u can use arrays.....
make sure there is no * in the whole program....

fun2sh said:
n which functions r not allowed??????????
user defined functions are not allowed....
u must make sure that there is only one header file <stdio.h>


Hurry......
time is running...
Answer will be given on NOV 23


Last day to answer the puzzle...
Will give answer tommorow....
Looks like i will get the point :D:D
 
Last edited:

fun2sh

Pawned!... Beyond GODLIKE
can we use this statement

Code:
char *string;

oh didnt read properly. cant use that statement :sad:

oh didnt read properly. cant use that statement :sad:
 
Last edited:
OP
A

adi007

Youngling
answer will given on next tuesday

(i have internals for the next 3 days :(:( and the answer program needs a lot of explanation).So,Three days extra time
EDIT:Answer in #69.Explanation and logic on next tuesday(Nov27).....
 
Last edited:

fun2sh

Pawned!... Beyond GODLIKE
@offtopic
HEY ADI also MINE 3rd INTERNAL R GOIN ON!!!
but me is givin only unix exam coz i got avg of (24-25)/25 in rest subject. i didnt study for unix in 2nd internal coz of illness


@ontopic

can we use global variable and this operator ::
 
OP
A

adi007

Youngling
Answer to puzzle 7
Code:
#include<stdio.h>
main()
{
char a[1000];
printf("Enter the string\n");
gets(a);
printf("Enter the character whose frequency is to be determined\n");
scanf("%c",&a[997]);
a[998]='0';a[999]='0';a[1000]='0';
for(;a[(a[998]-48)]!='\0';a[998]++)
 {
       if(a[997]==a[(a[998]-48)])
            a[1000]++;
 }
a[998]--;
for(;a[(a[999]-48)]!='\0';a[999]++)
 {
   if (a[(a[999]-48)]!=a[(a[998]-48)])
        {
        printf("\n%s is not a palindrome\n",a);
        break;
        }
   a[998]--;
 }
if(a[(a[999]-48)]=='\0')
      printf("\n%s is a palindrome\n",a);
for(a[998]='0';a[(a[998]-48)];a[998]++);
printf("The string \"%s\" contains %d characters and '%c' occurs %d times\n",a,a[998]-48,a[997],(a[1000]-48));
}

confused ??:confused::confused::confused::confused::
Don't worry.All explanation will be given on next tuesday....

fun2sh said:
@offtopic
HEY ADI also MINE 3rd INTERNAL R GOIN ON!!!
but me is givin only unix exam coz i got avg of (24-25)/25 in rest subject. i didnt study for unix in 2nd internal coz of illness
@offtopic
We have only 2 internals and the marks are added without reduction.Internals is for 20 marks.So 20+20+5(assignments)+5 (teachers wish)=50.The final exam will be condected for 100 marks and will be reduced to 50.
Sick.isn't it :sad::sad::sad:

fun2sh said:
@ontopic
can we use global variable and this operator ::
Sorry:( i didn't read this post .I just typed the program and tested and posted it without refreshing the thread....
 
Last edited:

fun2sh

Pawned!... Beyond GODLIKE
wel i was also doin this but usin a global variable, coz global variable is different from local 1. so i can use same name for both hence only one variable name is required.
but wat if i give a string greater than 1000 chars???
se usin global variable this wont be a problem as we can use locale to store the string while global to do the things u hav done.
 
OP
A

adi007

Youngling
I think 1000 is far more than sufficent for a string.....
If u declare a global and local variable with the same name then preference will be given to local variable.....
SO HOW CAN U USE BOTH OF THEM IF THEY ARE OF SAME NAME???:confused:
 

fun2sh

Pawned!... Beyond GODLIKE
that wat i was askin!!!

u can use a global variable usin :: operator

forexample 'a' is a global variable n local to
so
'a' will mean local
while
::a wil mean global
 
OP
A

adi007

Youngling
good info fun2sh..Didn't knew this
please post it in the lesser known facts in c thread ....

adi007 said:
Hi! I am Adithya U,17 year old Engineering Student(IT) from Hassan,Karnataka

Currently you are witnessing C puzzle 8


First,let me state the rules in this thread:
1.Please do not give suggestions or hints.Specify the modified program only.
2.Before posting the program make sure it's working in the way i want.


Here is the 8th C puzzle

Write a c program which gives accepts words and at the end of a word,it will replace the word by it's reverse.This is done until a smiley is encountered.At the end it will print "Have a nice day".That is if i entered i luv c and i think it's rocks :) will give the output as..

Enter the string
i vul c dna i kniht s'ti skcor :)
Have a nice day

to be more explainable

Code:
Enter the string
i luv_
as soon i press space,it will become

Code:
Enter the string
i vul _

There are no rules for this puzzle

Note :Specify your modified program along with the answer

Awards gallary:
Puzzles solved :7
me (If no one gets the solution then points will be for me) 2
saurabh kakkar 2
fun2sh 2
eggman 1
nigthtcrawler 1
Leading:saurabh kakkar,fun2sh and myself
puzzle 8 added!Thread updated
 
Last edited:

Faun

Wahahaha~!
Staff member
its easy man, may be if i'll get time will post here

Common interview question.

Btw am not a C fanatic
 
OP
A

adi007

Youngling
QwertyManiac said:
Until [noparse]:)[/noparse] is typed in.
no...
smiley means smiley[:)] not [noparse] this -->:)[/noparse]
read this *www.thinkdigit.com/forum/showpost.php?p=654017&postcount=21

T159 said:
its easy man, may be if i'll get time will post here

Common interview question.

Btw am not a C fanatic
Believe me it's not so easy...:D:D:D
 
Last edited:

Faun

Wahahaha~!
Staff member
adi007 said:
no...
smiley means smiley[:)] not [noparse] this -->:)[/noparse]
read this *www.thinkdigit.com/forum/showpost.php?p=654017&postcount=21


Believe me it's not so easy...:D:D:D
I hav done revesing the string.

Clarify some points:

Will there be upper bound to the length of the string ? or link list will be used ?
And that smiley thing will be ASCII code or a real jpeg file ?

I really dont like C :D:D:D, here is the bad code, someone can refine it further (I hav forgotten a lots of things in C):

#include<stdio.h>
#include<stdlib.h>

int recReverse( char *tempStrPtr )
{
int finalInt;

if (tempStrPtr == NULL)
finalInt = 0;
else if (*tempStrPtr == '\0')
finalInt = 0;
else if (*tempStrPtr == ' ')
finalInt = 0;
else
finalInt = recReverse(tempStrPtr+1)+1;

if(finalInt)
putchar(*tempStrPtr);
return finalInt;
}


int main ( )
{
char initStrPtr[20],*finalStrPtr;
int size=0;

gets(initStrPtr);

finalStrPtr=initStrPtr;

int incr=0;

while(finalStrPtr && *finalStrPtr)
{
incr = recReverse(finalStrPtr);
finalStrPtr += incr;

if(*finalStrPtr==' ')
{
putchar(' ');
finalStrPtr++;
}
}
return 0;
}

The Output, with stack overflow:

jit@jit-desktop:~$ ./a.out
i love c and i think it rocks
*** stack smashing detected ***: ./a.out terminated
i evol c dna i kniht ti skcorAborted (core dumped)
The Bad:
1) This thing will overflow like hell
2) gets() is a dangerous escape
3) No smiley return


to be more explainable

Code:
Enter the string
i luv_​

as soon i press space,it will become // you hav already pressed spacwe before, how will the program know that this space is the end

Code:
Enter the string
i vul _​
 
Last edited:
OP
A

adi007

Youngling
1.This program cannot be solved in Linux.Because u will not get a smiley in linux.You will get the smiley in TC.
2.There is no seperate input and output.The program is dynamic.

T159 said:
to be more explainable

Code:
Enter the string
i luv_​

as soon i press space,it will become // you hav already pressed spacwe before, how will the program know that this space is the end

Code:
Enter the string
i vul _​
^^underscore represents the cursor position

T159 said:
I hav done revesing the string.

Clarify some points:
And that smiley thing will be ASCII code or a real jpeg file ?
use CTRL B in TC editor and u will see yourself....

T159 said:
Will there be upper bound to the length of the string ?
^^yes
 
Last edited:

fun2sh

Pawned!... Beyond GODLIKE
hey can u give more examples of output involvin smiley. i m not gettin wat u want to do with smiley.
 
Status
Not open for further replies.
Top Bottom