dkalita 110 Posting Pro in Training

1) suggest you define macros STDIN and STDOU instead of hardcoding 0 and 1 in the read/write statements

#define STDOUT  1
#define STDIN   0

2) use sizeof operator to get the size of data

write( STDOUT, buf4, strlen(buf4) );
    read( STDIN, myArr[i].gender, sizeof(myArr[i].gender) );
    write( STDOUT, buf5, strlen(buf5) );
    read( STDIN, myArr[i].status, sizeof(myArr[i].status) );

[edit] And what they said above ^^^^ [/edit]

Hi,
Please consider the following example code

char a, c;
scanf("%c", &c);
scanf("%c", &a);
//printf("[c:%c, a:%c]\n", c, a);

when we run it the second scanf() statement takes the '\n' that is entered while entering a character for the first scanf().
It may be because the input buffer is not reset after the first scanf().
But I tried doing an fflush(stdin) before the second scanf() and it still doesn't take the second input.
Can u put some light on this issue.

Thanks in advance

dkalita 110 Posting Pro in Training

its because u r taking only one character in the read for the gender. After u enter m/f when u hit enter key it actually takes the '\n' as an input for the next read statement. Hence the next read() is skipped.

write( 1, buf4, strlen(buf4) );
read( 0, myArr[i].gender, 1 );   
write( 1, buf5, strlen(buf5) );
read( 0, myArr[i].status, 1 );

correct your code as

write( 1, buf4, strlen(buf4) );
read( 0, myArr[i].gender, 2 );// replaced 1 with 2   
write( 1, buf5, strlen(buf5) );
read( 0, myArr[i].status, 2 );// replaced 1 with 2

Also increase the buffer size for gender and status by 1.

it will work...........

dkalita 110 Posting Pro in Training

i m making a messenger in linux. a command line application. here is a server and 2 clients.both the clients are connected to the server but not with each other. i want to connect those 2 clients with each other. i m the server. how can i do that?


plz tel me a way out.

thanx

In the server u have to maintain a list of the connected client sockets. U can send this list(with some alias for display as name say) to the clients. The clients will chose from the list and then u can try writting to that socket from the client itself.
I have never tried this in C/C++ though.
But i think u can give a try.
This was just a suggestion. I am not very sure about its workability.

dkalita 110 Posting Pro in Training

yes but that should be copy the index which isn't space or tab but see now i changed to use index array members rather than addresses it worked fine i want to know why ?

#include <stdio.h>
#include <ctype.h>
#define STOP -1
int GetLine(char *SzBuff) {
    int i=0;
    char c;
    for( i=0;(c=getchar())!='\n';i++) {
        SzBuff[i]=c;
        if(c==EOF)  {
            SzBuff[i]='\0';
            return -1;
        }
    }
    SzBuff[i]='\0';
    return i;
}
int IsDel(char c) {
    if(c==' ' || c=='\t')   return 1;
    return 0;
}
void RemoveBlanks(char * SzString) {
    int j=0;
    for(int i=0;SzString[i]!=0;i++)
        if(!IsDel(SzString[i]))
            SzString[j++]=SzString[i];
    SzString[j]='\0';
    return;
}
int main(void)
{
    char SzName[100];
    while(GetLine(SzName)!=STOP) {
        RemoveBlanks(SzName);
        if(SzName[0]=='\0')//skip blank lines
            continue;
        puts(SzName);
    }
    return 0;
}

hi i got the problem. u used

SzString++;
previously which moves the char * by one character. If previously u had
p = "this";
p++;
// p will now point to the string "his" only............

that was the only problem........

dkalita 110 Posting Pro in Training

u are modifying the input string before checking the whole of it in the method RemoveBlanks() as follows:

while(*SzString) 
{
        if(!IsDel(*SzString))
        { //wtf why the hell does it keep incrementing !!!        
             SzString[j++]=*SzString;
            //putchar(SzString[j]);//used for debug
            //getchar();
            //j++;
        }
        SzString++;
      //this should ****en end the loop why the hell it keep going on incrementing
}

better take a temp string and put the characters in there and finlly modify the inputted string

dkalita 110 Posting Pro in Training

use a typecast in the throw tag

throw (char *)"Value is zero";

it should work. I have tried in my machine by using it.

dkalita 110 Posting Pro in Training

check the following part of your program in the GetLine() method.

for( i=0;(c=getchar())!='\n';i++) 
{
        SzBuff[i]=c;
        if(c==EOF)  return -1;
}

when u reach EOF u have not terminated your string with '\0'
try

for( i=0;(c=getchar())!='\n';i++) 
{
        SzBuff[i]=c;
        if(c==EOF)
        {
               SzBuff[i] = 0;// newly added
               return -1;
        }
}

the above may be a reason...............try

dkalita 110 Posting Pro in Training

There's nothing more to realy see..I gave out all the needed info the rest is just printf /scanf bla bla bla..
I just need help with the last line in my post..

when it comes to pointers to pointer it becomes a little difficult to asssume the thing thats why i asked for the whole program so that i can run it and see whats the problem.

thanks

dkalita 110 Posting Pro in Training

can u post your program or mail it to me so that i can have a look at it to dharmendra.kalita@ge.com

dkalita 110 Posting Pro in Training

what he says is correct.
U r only checking for the root.
yor function should be something like

int isbal(BST_t *root)
{
   if( root )
   {

        hr=height( root -> right);
        hl=height( root -> left );
        if(!((hr - hl) >= -1 && (hr - hl) <= 1))
                 return 0;
        else
                 return (isbal(root->left) && isbal(root->right));
    }
    else
    {
         return 1;
     }
}

and also thoroughly check the condition
"if(!((hr - hl) >= -1 && (hr - hl) <= 1))"

dkalita 110 Posting Pro in Training

go through the program. U wil know where to modify.

dkalita 110 Posting Pro in Training

look at the following part of code that u have written.......

meter=km/km_per_meter;
cm=meter/meter_per_cm;
inches=cm/cm_per_inches;
feet=inches_per_feet;

u have never initialized the values in the RHS of the statements. e.g.

meter = km/km_per_meter;

here km = 0
km_per_meter = 1000
and (0/1000) = 0
hence when u r trying to print 'meter' u are getting a zero.

This is programming and the statements will be executed in the sequence they appear.

the mistake u did is the following

printf("Enter distance of city 1 in Km: ");
scanf("%d",&inches);

u should have written

printf("Enter distance of city 1 in Km: ");
scanf("%d",&km);

another mistake that u did is in the following line

feet=inches_per_feet;

it should have been

feet=inches/inches_per_feet;

hope that helps

dkalita 110 Posting Pro in Training

u first try the conversion of one form to another first.
After u have tested all of them in individual programs u can try to integrate them............