dkalita 110 Posting Pro in Training

Well there must be a way that I'm not seeing, because that get_customer function was supplied with the assignment.

u have to use fread() to read the whole structure and not an individual member. Then u can use the particular member.

dkalita 110 Posting Pro in Training

ok ok.
make the following change
(refer to line #19)

if(start==FALSE && spacePrinted==FALSE)                
{
                       putchar(' ');
                       spacePrinted = TRUE;
}

change the above codes to

if(start==FALSE && spacePrinted==FALSE)                
{
                       putchar(' ');
}
spacePrinted = TRUE;
dkalita 110 Posting Pro in Training
int get_customer(ifstream& inFile, int width)
{
    int i;
    char c;
	char temp[10];

	for(i=0;i<width;i++)
	{
	    inFile.get(c);
	    temp[i] = c;
	}

	return atoi(temp);
}

there is another concept called Endianness.
Do google about it.
Moreover, U are doing the conversion in a wrong way.
U are reading 4 bytes and not digits.


say there is a number 12 which is stored in memory as
0x0 0x0 0x0 0xC (in hex)
or it may be in the following pattern
0x0 0x0 0xC 0x0
(this depends on the endianness, big endian or little endian[READ MORE ON IT])

what u are doing is storing these in a char array. Hence the character array becomes
{0, 0, 0, [junk]} [junk] ---> whose ascii is 12.

now when u do atoi(). U will obviously get 0.

Another important thing:
How do u know that your integer data starts from the very beginning of the file ?
U need to read more on file operation ....specially binary files.

dkalita 110 Posting Pro in Training

still nothing

hi, i tried the following program in my pc and it compiled successfully.

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{

  char encryptit(int x, char c[80]);

  int key = 5;
  char string[81];

  gets(string);

  encryptit(key , string);

  system("PAUSE");
  return 0;
}

char encryptit(int codekey, char stringydoo[80] ) /* Encrypt Header line */
{
      int i,stringnums[80];

      for(i=0; i<80; i++)
      {
           stringnums[i] = stringydoo[i];
           if (stringnums[i]>=32 && stringnums[i]<=126)
           {

                               stringnums[i] = stringnums[i]+ codekey;

                                                  if (stringnums[i]>=126)
                                                  {
                                                                           stringnums[i] = 32 + (stringnums[i]%126);
                                                  }

           stringydoo[i] = stringnums[i];
           }


      }


      puts(stringydoo);
      system("PAUSE");
}
dkalita 110 Posting Pro in Training

this still add one space after the first letter :S
input

kjkkk	kjkj		jj

output

k jkkk kjkj jj

its a bit strange

hi, i figured it out. See below

int spacePrinted=FALSE;

change the above line to

int spacePrinted=TRUE;

It will not print the space now.....................

dkalita 110 Posting Pro in Training
FILE* fd;
fd=fopen("salesbin.bin","wb");
fwrite((struct salesRecord*) sales, sizeof(struct salesRecord), 196, fd);
fclose(fd);

are u using fread() for reading your data.
Its obvious that when u open your file using some editor u wont see the exact values u are storing. U can see the characters because a character is stored as a byte and your editor(using which u open your file) will display it in original form only. But other data will be junks only or it wont mean what u see.

dkalita 110 Posting Pro in Training

following is the complete program for your purpose

#define FALSE 0
#define TRUE 1

void VymazBiele()
{
    int c;
    int start= TRUE;
    int spacePrinted=FALSE;
    while ( (c = getchar() ) != EOF )
    {
        if (isspace(c))
        {
          spacePrinted = FALSE;
          while ( (c = getchar() ) != EOF && isspace(c))
          {}
        }
          if (c != EOF)
          {
                if(start==FALSE && spacePrinted==FALSE)
                {
                       putchar(' ');
                       spacePrinted = TRUE;
                }
                putchar(c);
                if(c == '\n')
                     start = TRUE;
                else
                     start = FALSE;
          }
    }
}

things like this u should try on your own.

dkalita 110 Posting Pro in Training

hi there is already one library method in unistd.h called encrypt() hence it is giving the problem.
Change the function name to something else like encryptit().
It should work.

Sapreaver commented: Thank you +1
dkalita 110 Posting Pro in Training

try making your declaration before main (not inside main)

dkalita 110 Posting Pro in Training

check line #6:

char encrpyt(int , char);

the parameters are int and char.
In line #20

char encrypt(int codekey, char stringydoo[80] ) /* Encrypt Header line */

now the params are one int and a char [].

correct the prototype at line #6.

dkalita 110 Posting Pro in Training

pthread.h: no such file

pthread.h is generally for POSIX systems like FreeBSD, NetBSD, GNU/Linux, Mac OS X and Solaris, but Microsoft Windows implementations also exist. For example, the pthreads-w32 is available and supports a subset of the Pthread API for the Windows 32-bit platform.

If you are working in windows it wont work. U have to look for
pthreads-w32 .

checkout the link
http://en.wikipedia.org/wiki/POSIX_Threads

dkalita 110 Posting Pro in Training

when u include a file in <> brace like follows

#include <mutex.h>

it looks in the include directory.
But your file mutex.h is in your current directory. To include such file u have to do it using ""

#include "mutex.h"
dkalita 110 Posting Pro in Training
if(number = 0){}

what do u expect it do do?
That is an assignment statement. Read how to compare numbers.....

U are doing

number = number%16;

u are getting the least significant digit by that and u are loosing the remaining number.
U should have done

digit = number%16;
number = number/16;
/*compare digit now*/

here is how u can solve your problem in short

void itox(char hex[], int num)
{
     int digit;
     int i=0;
     whle(num>0)
     {
        digit = num%16;
        num = num/16;
        if(digit<10)
              hex[i++] = digit + '0';
        else
             hex[i++] = digit -10 + 'A';
     }
     if(i==0)/*if the number was less than 1*/
        hex[i++] = '0';
     hex[i] = '\0';
     /*reverse the string*/
    reverseStr(hex);
}
void reverseStr(char str[])
{
   int i, j;
   char c;
   for(i=0, j=strlen(str)-1; i<j; i++, j--)
   {
      c = str[i];
      str[i] = str[j];
      str[j] = c;
   }
}
dkalita 110 Posting Pro in Training

Will
multimap<string, string>
behave as this one is doing.

Thanks a lot

yep it should.

dkalita 110 Posting Pro in Training

it cannot be like

mymm.insert(pair<char,int>("andrew","50 years old"));

it had to be

mymm.insert(pair<string, string>("andrew","50 years old"));

because the values u are passing are strings.

dkalita 110 Posting Pro in Training

Ya I was not removing the duplicates.

Thanks for your help :)

u welcome :)

dkalita 110 Posting Pro in Training

ofcource u will get duplicates because u are doing

for(itv=vec1.begin(); itv < vec1.end(); itv++){...}

and this vector contain all those character more than once.
U must skip those character which are already printed.

Dont do the following

vec1.push_back('a');    
vec1.push_back('b');     
vec1.push_back('b');        
vec1.push_back('b');          
vec1.push_back('c');            
vec1.push_back('c');              
vec1.push_back('d');                
vec1.push_back('e');                  
vec1.push_back('e');                    
vec1.push_back('e');                      
vec1.push_back('e');                        
vec1.push_back('e');                        
vec1.push_back('n');                          
vec1.push_back('k');                            
vec1.push_back('k');

push a character only once

vec1.push_back('a');    
vec1.push_back('b');     
vec1.push_back('c');              
vec1.push_back('d');                
vec1.push_back('e');                  
vec1.push_back('n');                          
vec1.push_back('k');
dkalita 110 Posting Pro in Training

Ok ok .. Thanks... I will try it :)
Any other suggestions ?
Now if I want to change my multimap from <char, int>
to <string, string > any suggestions ?

Thanks

yes you can do it easily. Post here if you get any issues.

One more suggestion is read about whatever u want to use. Use google. There are lot of materials available on net. :)
enjoy

dkalita 110 Posting Pro in Training

Sorry any example ?

see my prev post

dkalita 110 Posting Pro in Training

How can I reset it.. any example ?

Thanks

do it just at the beginning of your loop as follows:

for (c='a'; c<='z'; c++)  
{
      i=0;
      k=0;
/**remaining code/
}
dkalita 110 Posting Pro in Training

u are not resetting the variables i and k to zero and due to which the condition

if(i==0)

and

if(k==0)

fails after u have completely printed one character range.

dkalita 110 Posting Pro in Training

well but i will read multiple lines, so how to make this code right ?

set the start flag to TRUE when u get a newline ('\n') character.

dkalita 110 Posting Pro in Training

i try that ..
not work ^_^

do the initialisation in the default constructor then if u want.

dkalita 110 Posting Pro in Training

ok, i understand now, that it will not do putchar(' ') because the START has true value, so it will ignore all the white spaces until the first letter :)

but how to manage, that the output won't end with one space as it ends in this case.. i cant figure out how to replace last white space with \0, any ideas ?

use one more flag for that as

#define FALSE 0
#define TRUE 1

void VymazBiele()
{
int c;
    int start= TRUE;
    int spacePrinted=FALSE;
    while ( (c = getchar() ) != EOF )
    {
        if (isspace(c))
        {
          spacePrinted = FALSE;
          while ( (c = getchar() ) != EOF && isspace(c))
          {}
        }
          if (c != EOF)
          {
                if(start==FALSE && spacePrinted==FALSE)
                {
                       putchar(' ');
                       spacePrinted = TRUE;
                }
                putchar(c);
                start = FALSE;
          }
    }
}
dkalita 110 Posting Pro in Training

thats whats happen with me .

u mean
cin>>name;
worked in your compiler?

dkalita 110 Posting Pro in Training

Yes you can. But then you have an uninitialized variable in your program. That's a bad thing. That's why I said: string name="";

yes you are right but some compiler do not allow u to initialize a data member of a class like that.
Even I am getting the following error while trying to do so

error: ISO C++ forbids initialization of member `name'

This is the program that worked fine in my compiler(in linux)

#include<iostream>
#include<string>

using namespace std;

 class STD1{
         int id;
         string name;
          char status;
 public :
         void pinfo();
         void ginfo();
};
void STD1::ginfo(){
        cout<<"Enter ID : ";
        cin>>id;
        cout<<"\nEnter Name : ";
        cin>>name;
        cout<<"\nEnter Status : ";
        cin>>status;
}
void STD1::pinfo(){
        cout<<"Student Info Is ... ID : "<<id <<" Name : "<<name <<" Status : "<<status;
}

int main()
{
        STD1 m;
        m.ginfo();
        m.pinfo();
        return 0;
}

when i tried to use getline(cin, name) that statement is skipped. The user is not prompted for any input and goes for the next statement.

dkalita 110 Posting Pro in Training

i try this ,,
but the program skip this process
ask me to put the "status" Dirct .

are u getting still more errors. Put them in here then. Will have a look at it.

dkalita 110 Posting Pro in Training
string name="";

u can write

string name;
dkalita 110 Posting Pro in Training

hi,

just want to ask, is it possible to restrict friend acess to a single class member function only?

in other words, if class A grant class B friend access to class A member function, then class B can call that class A function.

*note: this is suppose to be a workaround to the inability (my own) to pass class member function pointers into another class.

thanks in advance!

nope. A friend class can access all the members of a class.

dkalita 110 Posting Pro in Training

but with that u will have only one char so do something like
char name[20];

dkalita 110 Posting Pro in Training
using std::cin;                //  using std::setprecision;
using std::cout;                 using std::string;
using std::endl;               //  using std::streamsize;

make it a one statement as

using namespace std;

I am not sure of why the error is coming because i tested the same in my machine in linux and it was working.

dkalita 110 Posting Pro in Training

By default the access specifier is private in a class and hence u are not able to access the ginfo() and pinfo() method of the class STD1.
U have to set them as public.
Do

public:
    void ginfo();
    void pinfo();
dkalita 110 Posting Pro in Training

I test ran your code and got the following output:

Enter the maze's dimensions separated by a comma.
Format x,y: 3
5

cout << maze[][].*Wall; in LoadMaze()

0,0 stores 1 1 1 1
0,1 stores 1 1 1 1
0,2 stores 1 1 1 1
1,0 stores 1 1 1 1
1,1 stores 1 1 1 1
1,2 stores 1 1 1 1
2,0 stores 1 1 1 1
2,1 stores 1 1 1 1
2,2 stores 1 1 1 1
3,0 stores 1 1 1 1
3,1 stores 1 1 1 1
3,2 stores 1 1 1 1
4,0 stores 1 1 1 1
4,1 stores 1 1 1 1
4,2 stores 1 1 1 1

cout << maze[][].*Wall; in main()
1

........................................................
I am not sure of why u r getting that 171 in your output...........

dkalita 110 Posting Pro in Training

may be u can do it as

void ConcreteVisitorA::VisitElement(Element e)
{
 
	int numNodes = e.GetNumNodes();
	int numAttrs = e.GetNumAttrs();
	cout << "Visitor has found " << numNodes << " noes\n";


              Visitor tempV;/*set all the necessary data members*/
	e.nodeVec[0]->Accept(tempV);
		
}
dkalita 110 Posting Pro in Training

its a good suggestion by dkalita.. if u dont want to change the return type u can call the switchuser function inside the if block as follow ...

void TicTacToe::postMove(int row, int col, char value)
{
if (theBoard[row][col] == '-')
{
theBoard[row][col] = value;
//call the switch user function here...then u can return to the block  // which called this function
}

else

cout << "Space is already taken, please choose a different one." << endl;
}

Cheers ,
saradha

u can do that. But it's not a good OOP practice.

dkalita 110 Posting Pro in Training
void TicTacToe::postMove(int row, int col, char value){
     if (theBoard[row][col] == '-'){
          theBoard[row][col] = value;
     }
     else
          cout << "Space is already taken, please choose a different one." << endl;

make the return type of the above function as bool. Return false if the space is already occupied.
Dont call the switchPlayer() method if postMove() returns false.

dkalita 110 Posting Pro in Training

there is no way other than that or making the head public.

U can write the third function with the same name without having any parameters.

dkalita 110 Posting Pro in Training

how do i do that? and their is still something wrong with the code. :(.

that answer was for your last post before you edited that.

Write a third function without any argument which calls your recursive function inside it passing the head.
Call this third function from main().

dkalita 110 Posting Pro in Training

declare your p as static in the show_sllist() method

dkalita 110 Posting Pro in Training
reverseArray(intArray,low,high);

what is the value of low and high. U didn't initialized them.
Would u plz first go through your code and do a dry run using pen and paper.

dkalita 110 Posting Pro in Training

check the prototype of the function reverseArray()

dkalita 110 Posting Pro in Training
month = atoi(strtok(s,"/,:\n"));
day = atoi(strtok(NULL,"/,:\n"));

u ingnored what i told u in my previous post in these lines.
If strtok() returns NULL u will have atoi(NULL)

dkalita 110 Posting Pro in Training

and plz, can u explain me, why using your code was more successful than mine ? what did that #define TRUE, #define FALSE do excactly /, and using this in the code, i relly want to understand it

read more on macros in C

dkalita 110 Posting Pro in Training

use a flag for that as follows

#define FALSE 0
#define TRUE 1

void VymazBiele()
{
int c;
    int start= TRUE;
    while ( (c = getchar() ) != EOF )
    {
        if (isspace(c))
        {
          if(start==FALSE)
                 putchar(' ');
          while ( (c = getchar() ) != EOF && isspace(c))
          {}
          }
          if (c != EOF)
          {
                putchar(c);
                start = FALSE;
          }
    }
}
dkalita 110 Posting Pro in Training
strcpy(array[daysize]->appts[0]->subject, strtok(NULL,"/,:\n"));

avoid something like that. It might give segentation fault if there is no more tokens (strtok() returns NULL).

Make a check before doing any operation on the string pointed to by the address returned by the strtok() function.

char *c = strtok(NULL, "/,:\n");
if(c!=NULL)
       /*proceed*/
dkalita 110 Posting Pro in Training

try it as follows

Window *w=(Window *)it->second;
/*or (Window *)(it->second)      if the former gives error*/
w->getTitle();
dkalita 110 Posting Pro in Training

make the following correction in main()

for(i=0;i<n;i++)
{
      scanf("%d",&array[i]); /*& added*/
}
dkalita 110 Posting Pro in Training

hello, can somebody help me in learning file i/o in c++?
i would be very grateful

just google it

dkalita 110 Posting Pro in Training

ok. i got ur point. but one more question plz. only one client needs to connect with the other client. or both of the clients need to call the command connect() ? in other words i need to send that socket to only 1 client or to the both?

don't do a connect() from a client to client directly.
A client will always connect to the central server. Design your protocol in a manner as follows:

client ----------- connect() ---------> server
........................................(add the incoming client socket to a list)
client <------(client socket list)--- server
client --------particular socket----> server
(choose from other socket list)
client <----------ack------------------ server
(now this client have the particular socket where to write which the other client will read from, so just start writting to this socket.)

**** The above is not a full fleged protocol because it is not sending any info to the other client.
So first design your protocol properly, then only u should go for the implementation.

U have to design different message formats, say MSG_ACK, MSG_SOCKLIST, MSG_TEXT, etc.

May that help.

adcodingmaster commented: a very good and detailed answer. i got that very clear now. thnx a lot sir +1
dkalita 110 Posting Pro in Training

oh thanks man i thought addresses is same as indexes but i guess i was wrong

u r welcome.......