C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 07-04-2008, 05:51 AM   #16
Deathray Engineer
 
MacGyver's Avatar
 
Join Date: Mar 2007
Posts: 3,211
Quote:
Originally Posted by @nthony View Post
requesting obligatory posting of mac's signature and lock... in that order.
You rang, sir?
__________________
MacGyver is offline   Reply With Quote
Old 07-04-2008, 07:03 PM   #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   Reply With Quote
Old 07-07-2008, 01:18 AM   #18
Registered User
 
Join Date: Jul 2008
Posts: 38
Smile I dont really understand subquestion L

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   Reply With Quote
Old 07-07-2008, 03:30 AM   #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   Reply With Quote
Old 07-07-2008, 03:41 AM   #20
CSharpener
 
vart's Avatar
 
Join Date: Oct 2006
Posts: 5,242
Quote:
BLUR = BLUR[0]
not exactly

Code:
 BLUR == &BLUR[0]
__________________
If I have eight hours for cutting wood, I spend six sharpening my axe.
vart is offline   Reply With Quote
Old 07-07-2008, 04:49 AM   #21
Registered User
 
Join Date: Apr 2008
Posts: 83
Quote:
Originally Posted by mkdl750 View Post
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;
}

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   Reply With Quote
Old 07-08-2008, 04:51 AM   #22
Registered User
 
Join Date: Jul 2008
Posts: 38
Okay now please show the memory diagram in subquestion L.
mkdl750 is offline   Reply With Quote
Old 07-08-2008, 04:53 AM   #23
Woof, woof!
 
zacs7's Avatar
 
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
__________________
"I.T. gets the chicky-babes" - M. Kelly
bakefile | vim
zacs7 is offline   Reply With Quote
Old 07-10-2008, 08:01 PM   #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);
}
But how can I display the number of letters with even ASCII character values?
mkdl750 is offline   Reply With Quote
Old 07-10-2008, 09:47 PM   #25
Deathray Engineer
 
MacGyver's Avatar
 
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   Reply With Quote
Old 07-11-2008, 12:56 AM   #26
Registered User
 
Join Date: Jul 2008
Posts: 38
any further assistance about my answer to subquestion E?
mkdl750 is offline   Reply With Quote
Old 07-11-2008, 10:34 AM   #27
and the Hat of Guessing
 
tabstop's Avatar
 
Join Date: Nov 2007
Posts: 8,740
  1. There is no such thing as "main()". There is "int main()", and there is "int main(int argc, char *argv[])".
  2. Indentation is something you should look into. Basically: everything inside curly braces should be moved over by the same amount (and the more braces, the further over you go).
  3. A string (which should probably not be called "x") can be either char *x, or char x[20], but not both. The declaration char *x[20] gives you 20 pointers-to-characters; each pointer-to-character could be a string one day, if you malloc'ed memory for those pointers to point to.
  4. %c only reads one character from standard input. %s will read in a string, provided it has no spaces, but needs work to be safe. There is such a thing as fgets.
  5. There's no need to call the function twice -- once inside the print statement should be sufficient.
tabstop is offline   Reply With Quote
Old 07-11-2008, 10:53 AM   #28
Rampaging 35 Stone Welsh
 
abachler's Avatar
 
Join Date: Apr 2007
Posts: 2,927
Code:
 
char Dec(char a){
   return 64 + (((63 & a)+ 1) % 26);
   }
do I win a cookie ?
__________________
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   Reply With Quote
Old 07-13-2008, 07:04 PM   #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   Reply With Quote
Old 07-13-2008, 07:17 PM   #30
Registered User
 
Join Date: Oct 2007
Posts: 242
Quote:
Originally Posted by mkdl750 View Post
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);
}
Your algorithm is correct but the way you are calling it is wrong.
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   Reply With Quote
Reply

Tags
assignment, c programming, homework

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 06:42 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22