QwertyManiac
Commander in Chief
He meant creating just strings using arrays and one's not allowed to create a sub-routine to process things.
then how will one store a string (as arrays are also pointers)adi007 said:No pointers,functions,structures,unions......
no constants...QwertyManiac said:Only 1 variable but constants are allowed as desired?
arrays are not pointers..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??????????
user defined functions are not allowed....fun2sh said:n which functions r not allowed??????????
EDIT:Answer in #69.Explanation and logic on next tuesday(Nov27).....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
#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));
}
@offtopicfun2sh 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
Sorry i didn't read this post .I just typed the program and tested and posted it without refreshing the thread....fun2sh said:@ontopic
can we use global variable and this operator ::
puzzle 8 added!Thread updatedadi007 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
as soon i press space,it will becomeCode:Enter the string i luv_
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
no...QwertyManiac said:Until [noparse][/noparse] is typed in.
Believe me it's not so easy...T159 said:its easy man, may be if i'll get time will post here
Common interview question.
Btw am not a C fanatic
I hav done revesing the string.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...
#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 Bad: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)
^^underscore represents the cursor positionT159 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 _
use CTRL B in TC editor and u will see yourself....T159 said:I hav done revesing the string.
Clarify some points:
And that smiley thing will be ASCII code or a real jpeg file ?
^^yesT159 said:Will there be upper bound to the length of the string ?