954,505 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Need Help With Some Programs

Guys I have to subit my lab record tommorow.....i just have some programs left which iam not able to do.:'(

1. Write a program to print the pascal triangle
2. Write a program to concatenate two strings without using teh library functions, by pointers
3. WAP to compare two strings without using library functions by using pointers
4. WAP a function opposite case , to convert accepted strings to pposite case

All these programs in C Language.....It'll be great if some can provide me with the solutions.....The strings chapter was actually not covered for us , so although we completed the entire C language iam not able to it and pascal triangle man its confusing .....I'd appreciate a lot if some one could provide the results.:)


And ya U guys may get annoyed ans say I dint even post what i solved.....what i solved is a whole blunder......

rollingstones
Newbie Poster
7 posts since Apr 2007
Reputation Points: 9
Solved Threads: 0
 

Sorry but we are not in the business of doing people's homework assignments for them.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

hey,
you have to show that you have actually tried to solve it by submitting the codes you've written... so that someone can help you where you have a knot.... that is how it is done here.

addicted
Junior Poster in Training
57 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 

Ya well i knew u guyz would reply like that....


here ya go...

#include <stdio.h>
#include <conio.h>
int mystrcmp(char *,char *);
void main()
{
int p;
char s1[10],s2[10];
clrscr();
printf("enter the first string\n");
scanf("%s",&s1);
printf("Enter the secong string\n");
scanf("%s",&s2);
p=mystrcmp(&s1,&s2);
 if(p==0)
  printf("Both are same\n");
 else
  printf("Both are different");
getch();
}
int mystrcmp(char *s1,char *s2)
{
 while(*s1==*s2)
  {
   if(*s1=='\0')
    return(0);
   s1++;
   s2++;
  }
 return((*s1)-(*s2));
}


I got it now.....but still dint get others will post what iam did from now....sorry for the trouble

rollingstones
Newbie Poster
7 posts since Apr 2007
Reputation Points: 9
Solved Threads: 0
 

Now what wrong with this code....its to concatenate or join two strings

#include #include int mystrcat(char *,char *); void main() { char s1[10],s2[10],s3[10]; clrscr(); printf("enter the first string\n"); scanf("%s",&s1); printf("Enter the second string\n"); scanf("%s",&s2); s3[10]=mystrcat(&s1,&s2); printf("%s",s3); getch(); } int mystrcat(char *s1,char *s2) { while(*s1!='\0') s1++; if(*s1=='\0') return((*s1)+(*s2)); }

No errors...byt the o/p is not being displayed

rollingstones
Newbie Poster
7 posts since Apr 2007
Reputation Points: 9
Solved Threads: 0
 

it would be very useful if you wrapped your text in code ()

Nichito
Posting Virtuoso
1,602 posts since Mar 2007
Reputation Points: 424
Solved Threads: 57
 

Alright mate....did it....

rollingstones
Newbie Poster
7 posts since Apr 2007
Reputation Points: 9
Solved Threads: 0
 

the thing is, in this function you are not concatenating the two strings, you are adding together two pointers, which does not solve the problem. what you must do is create a

char *s3


with the length of the two strings added together, and pass the characters one by one into the pointer...

Got it?

Nichito
Posting Virtuoso
1,602 posts since Mar 2007
Reputation Points: 424
Solved Threads: 57
 

ya i got it but not getting the correct code for it...

ur saying first loop
s3=s1
and second loop
s3=s2
and s3[last value]=='\0'...

the coding a little problomatic

rollingstones
Newbie Poster
7 posts since Apr 2007
Reputation Points: 9
Solved Threads: 0
 

nope... what i´m saying is that you s1 into s3 in the first cycle with a while loop. Then, without moving the pointer from the position next to the last character you entered in s3, you continue with s2, transferring characters into the rest of the spaces in s3, and in the end s3=='\0' like this:

while (*s1!='\0')
   *s3==*s1;
   s1++;
   s3++;
}
Nichito
Posting Virtuoso
1,602 posts since Mar 2007
Reputation Points: 424
Solved Threads: 57
 

Thanks Solved It..........Two programs left.....can anyone plz help with the pasal triangle...i searched this forum for pascal triangle and found very complex codes for it

rollingstones
Newbie Poster
7 posts since Apr 2007
Reputation Points: 9
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You