![]() |
| | #16 | |
| Deathray Engineer Join Date: Mar 2007
Posts: 3,211
| Quote:
__________________ | |
| MacGyver is offline | |
| | #17 |
| Registered User Join Date: May 2008
Posts: 12
| 2. Be able to demonstrate and explain programs to your lecturer. Even if we create the code for you, do you think you can able to explain it? |
| azerej is offline | |
| | #18 |
| Registered User Join Date: Jul 2008
Posts: 38
| Okay I'm done with subquestions A, B, C, D, and I really don't understand what memory diagrams are. I am asked to trace the following C program and write down its output. Can you kindly assist me in this one? Code: #include <stdio.h>
#include <conio.h>
char *B1, *B2, *B3, *B4, *B5;
char BLUR[8] = {'M', 'O', 'R', 'E', 'B', 'L', 'U', 'R'};
main()
{
clrscr();
B5=B4=BLUR;
++B4;
B3=&BLUR[6];
B2=B5+2;
B1=&BLUR[7]-3;
printf ("%c\t%c\t%c\t%c\t%c",*B1,*B2,*B3,*B4,*B5);
getch();
return 0;
}
|
| mkdl750 is offline | |
| | #19 |
| Registered User Join Date: Mar 2008 Location: India
Posts: 70
| B5=B4=BLUR 1) B5 and B4 are pointers to characters 2) BLUR = BLUR[0] I think that above two points will help you to calcuate the output. |
| vlrk is offline | |
| | #20 | |
| CSharpener Join Date: Oct 2006
Posts: 5,242
| Quote:
Code: BLUR == &BLUR[0]
__________________ If I have eight hours for cutting wood, I spend six sharpening my axe. | |
| vart is offline | |
| | #21 | |
| Registered User Join Date: Apr 2008
Posts: 83
| Quote:
The output of following program is :- B R U O M Code:
#include <stdio.h>
#include <conio.h>
char *B1, *B2, *B3, *B4, *B5;
char BLUR[8] = {'M', 'O', 'R', 'E', 'B', 'L', 'U', 'R'};
int main()
{
B5=B4=BLUR;//Both Pointers are assigned to 'M'
++B4; //Now it will point to 'O'
B3=&BLUR[6]; //'U' has been assigned
B2=B5+2; //'R' has been assigned
B1=&BLUR[7]-3; //'B' has been assigned
printf ("%c\t%c\t%c\t%c\t%c",*B1,*B2,*B3,*B4,*B5); //B R U O M
getch();
return 0;
}
| |
| shwetha_siddu is offline | |
| | #22 |
| Registered User Join Date: Jul 2008
Posts: 38
| Okay now please show the memory diagram in subquestion L. |
| mkdl750 is offline | |
| | #23 |
| Woof, woof! Join Date: Mar 2007 Location: Australia
Posts: 3,139
| > Okay now please show the memory diagram in subquestion L. Negative. http://pages.cs.wisc.edu/~cs302/reso..._diagrams.html |
| zacs7 is offline | |
| | #24 |
| Registered User Join Date: Jul 2008
Posts: 38
| Heres my draft solution for subquestion E. Code: #include <stdio.h>
#include <string.h>
int CountEvenASCII(char *str);
main()
{
char *x[20];
printf("Enter a string of letters: ");
scanf("%c",x);
CountEvenASCII(*x);
printf("%d",CountEvenASCII(*x));
getch();
return 0;
}
int CountEvenASCII(char *str)
{
if(str[0] == '\0')
return 0;
if((int)str[0] % 2 == 0)
return 1 + CountEvenASCII(str + 1);
else
return CountEvenASCII(str + 1);
}
|
| mkdl750 is offline | |
| | #25 |
| Deathray Engineer Join Date: Mar 2007
Posts: 3,211
| That code is horrible. If someone taught you to write that, they did you a disservice.....
__________________ |
| MacGyver is offline | |
| | #26 |
| Registered User Join Date: Jul 2008
Posts: 38
| any further assistance about my answer to subquestion E? |
| mkdl750 is offline | |
| | #27 |
| and the Hat of Guessing Join Date: Nov 2007
Posts: 8,740
|
|
| tabstop is offline | |
| | #28 |
| Rampaging 35 Stone Welsh Join Date: Apr 2007
Posts: 2,927
| Code:
char Dec(char a){
return 64 + (((63 & a)+ 1) % 26);
}
__________________ He is free, you say. Ah! That is his misfortune… These men… [have] the most terrible, the most imperious of masters, that is, need. … They must therefore find someone to hire them, or die of hunger. Is that to be free? - Simon Linguet Last edited by abachler; 07-11-2008 at 10:56 AM. |
| abachler is offline | |
| | #29 |
| Registered User Join Date: Jul 2008
Posts: 38
| Can you help me correct this code? Code:
#include <stdio.h>
#include <string.h>
int CountEvenASCII(char *str);
main()
{
char *x[20];
printf("Enter a string of letters: ");
scanf("%c",x);
CountEvenASCII(*x);
printf("%d",CountEvenASCII(*x));
getch();
return 0;
}
int CountEvenASCII(char *str)
{
if(str[0] == '\0')
return 0;
if((int)str[0] % 2 == 0)
return 1 + CountEvenASCII(str + 1);
else
return CountEvenASCII(str + 1);
}
|
| mkdl750 is offline | |
| | #30 | |
| Registered User Join Date: Oct 2007
Posts: 242
| Quote:
This should be done just like the following (check out the changes in CountEvenASCII) Code: int CountEvenASCII(const char *str) // since you are not making any changes to the string, it's supposed to be a constant string.
{
if(str[0] == '\0')
return 0;
if((int)str[0] % 2 == 0)
return 1 + CountEvenASCII(str + 1);
return CountEvenASCII(str + 1); // no 'else' is needed.
}
int main(void)
{
const char *abc = "AB";
printf("%d", CountEvenASCII(abc));
return 0;
}
| |
| eXeCuTeR is offline | |
![]() |
| Tags |
| assignment, c programming, homework |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Homework | kermi3 | A Brief History of Cprogramming.com | 11 | 11-03-2001 04:39 PM |
| Homework | kermi3 | C Programming | 10 | 09-27-2001 04:49 PM |
| Homework | kermi3 | C++ Programming | 15 | 09-26-2001 03:16 PM |
| Homework | kermi3 | Windows Programming | 5 | 09-15-2001 11:48 AM |
| Homework | kermi3 | C Programming | 0 | 09-10-2001 01:26 PM |