Prabakar 77 Posting Whiz

I am confused looking at this thread. To convert a lower case letter to upper case I always subtracted 32 from the lowercase letter. Adding 48? Is this correct or is it a mistake.
Please reply.

jephthah commented: good catch +1
Nick Evan commented: Thanks for the correction. You're right +6
Prabakar 77 Posting Whiz

I am learning a lot after I entered this forum. Thanks a lot, and then why so harsh, I am scared reading this.

Prabakar 77 Posting Whiz

Well, I would like to start by giving the same advice I recived here. Dont use conio.h and the turbo c compiler.
And Never Ever Use void main() search void main in this website & you woud know why.

And as for your question, you read values till rows & cols & print the answers till MAX_ROWS & MAX_COLS

And finaly, you should learn to intend as jephthah said It will help you a lot.

Prabakar 77 Posting Whiz

To check Wheather a no 'n' is prime or not why not check if 'n' is divided by the prime numbers from 2 to sqrt of the number 'n'?
It would prove better

Prabakar 77 Posting Whiz

Preety simple.
Enqueue:
Get a data & then push it on to stack 1. squeeze stack1 like a lemon till it dries & collect them in stack 2.
Dequeue:
Squeeze stack2 this time & collect in stack1
pop the data from stack1.
I leave one more important point for you to figure out.

Prabakar 77 Posting Whiz

I made a game in Win32 but it was quite difficult. It is called the 'SameGame' or commonly known as bubblebreaker mainly for phones, It might just give you an idea of how difficult it is to make these kind of games using Win32.

So I see, You will never seize to surprise me. Thanks a lot.

Prabakar 77 Posting Whiz

If you use dynamic allocation because I told you, then I am sorry, because I ment to use dynamic allocation for the random array. Since, every time you allocate a cluster of memory from the heap and is bound to be different form the previous one.

Prabakar 77 Posting Whiz

Ya. You should give importance to the no of bytes you recive.

Prabakar 77 Posting Whiz

<<then the program will print to the result.txt A (last line ,transformed)
The reason why this happens is that the push() uses everytime the same buffer (=record), so effectively the stack contains pointers to this single buffer, and what was last written to the buffer, gets printed to the file as many times as pop() is called.

Ya, he's correct, I missed it completly, perhaps use dynamic allocation. That should work.

Prabakar 77 Posting Whiz

Well, I guess this should me the final modification!!!

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define isdigit(d) ((d)>47 && (d)<58) ? 1 : 0
#define isalpha(d) (((d)>='A' && (d)<='Z') || ((d)>='a' && (d)<='z'))?1:0
#define MAXSTACK 10
#define EMPTYSTACK -1
//------------------------------------------------------------------------------
void AD(char * record, char * record_out)
{
    char *p1 = record, *p2 =  record_out;
    while( *p1 != '\r' ) 
    {
       if ( isdigit(*p1) ) {
            p1++ ;
            continue ;
       }
       *record_out++ = *p1++;
    }
    *record_out++ == *p1 ;
    *record_out = '\0' ;
}
//------------------------------------------------------------------------------
int count (char vector[],int nr)

{
    int gasit=0,i; 
    for(i=0;i<nr;i++)
        if ( isalpha ( vector[i] ) ) gasit++ ;
    return gasit;

}
//------------------------------------------------------------------------------
char *fill_buffer(char *filename)
{
  FILE *fp;
  long filesize;
  char *buffer;

  if (!(fp = fopen(filename, "rb")))
    {
      printf("mistake: can't open file\n");
      exit(EXIT_FAILURE);
    }

  fseek(fp, 0, SEEK_END);
  filesize = ftell(fp);
  rewind(fp);

  if (!(buffer = (char*)calloc(filesize + 1, sizeof(char))))
    {
      printf("mistake: memory problems.\n");
      exit(EXIT_FAILURE);
    }

  if (filesize != fread(buffer, sizeof(char), filesize, fp))
    {
      printf("mistake: can't read file\n");
      exit(EXIT_FAILURE);
    }
  buffer[filesize] = '\0';
  fclose(fp);
  return buffer;
};
char *items[10];
int top = EMPTYSTACK;
void push( char* );
char *pop();
int empty();
int full(); 
//==========================================================
void push(char *c) {
    items[++top] = c;
}

char *pop( )  {  
   return  items[top--];   
}


int full()  {
   return top+1 == MAXSTACK;
}

int empty()  {
   return top == EMPTYSTACK;
}
//------------------------------------------------------------------------------

int main(int argc, char **argv)
{
    char *DELIMITERS = "\n";  
	char *str, *buffer, *temp,*t;
	char record[100];
	char last_char;
	int kiek,ln;
	FILE *fr;
    int HOW=0;
	if (argc != 3) {printf ("wrong …
Prabakar 77 Posting Whiz

I'll reply a little later & then I didnt mean to hurt, sorry if I did.

And I have a strange question. What compiler do you use? Cause I would always be promted by the complier If I DEFINE a fn inside another fn.

Prabakar 77 Posting Whiz

Yes, and that's what I get for typing without testing.

I realised that it was a typo error , thats why I did not probe on it much. Any way, Isnt that insertion sort?

Prabakar 77 Posting Whiz

Excuse me, wont the second code make an infinte loop, I mean, 'i' will be less than n the whole time

Prabakar 77 Posting Whiz

And thanks for the comment

Prabakar 77 Posting Whiz

I am creating client-server application. In that server is continuously running and client sends Information to server.
When client exe executes... it calls clientinfo.exe& create info.txt
This clientinfo.exe about codecs, ip, system info.
But on some clients no codes are available.
So size of info.txt is varies i.e. size is 24kb/23kb/15kb/4kb


I am trying to send text file through the sendto() function from Client..
But I am still getting info.txt file data + garbage data on the Server side...
How to get data without garbage value???

I am glad that the first is solved.

What function to you use to get the data from info.txt. in client side

And thanks for the comment.

Prabakar 77 Posting Whiz

Give your mind a thought first.

Prabakar 77 Posting Whiz

I modified the code, without changing the structure much.
And it worked. Some functions looked meaningless to me & so I removed them.

Here is the code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include<ctype.h>
#define MAXSTACK 10
#define EMPTYSTACK -1

char *fill_buffer(char *);
void push( char* );
char *pop();
int empty();
int full();  

char *fill_buffer(char *filename)
{
  FILE *fp;
  long filesize;
  char *buffer;

  if (!(fp = fopen(filename, "rb")))
    {
      printf("mistake: can't open file\n");
      exit(EXIT_FAILURE);
    }

  fseek(fp, 0, SEEK_END);
  filesize = ftell(fp);
  rewind(fp);

  if (!(buffer = (char*)calloc(filesize + 1, sizeof(char))))
    {
      printf("mistake: memory problems.\n");
      exit(EXIT_FAILURE);
    }

  if (filesize != fread(buffer, sizeof(char), filesize, fp))
    {
      printf("mistake: can't read file\n");
      exit(EXIT_FAILURE);
    }
  buffer[filesize] = '\0';
  fclose(fp);
  return buffer;
};

int top = EMPTYSTACK;
char *items[10];

void push(char *c) {
    items[++top] = c;
}

char *pop( )  {  
   return  items[top--];   
}

int full()  {
   return top+1 == MAXSTACK;
}

int empty()  {
   return top == EMPTYSTACK;
}
    
int main(int argc, char **argv)
{
                char *DELIMITERS = "\n\r 1234567890";  // check for digits & space
	char *str, *buffer, *temp,*t;
	char record[100];
	char last_char;
	int kiek,HOW = 0;
 	FILE *fr;
	if (argc != 3) {printf ("wrong parameters\n"); return 0;};
	buffer = fill_buffer(argv[1]);	
	str = strtok(buffer, DELIMITERS);

	if ((fr = fopen(argv[2], "w")) == NULL) 
	{
		printf("mistake: can't open file for writing\n");
		return 0;
	};

	while (str)
	{
                        if (!full()) push(str);
                        HOW++ ;
	        str = strtok(NULL, DELIMITERS);
                 }	

                 while (!empty())
                       fprintf(fr,"%s\n", pop());	
	 fprintf(fr,"\n");
	 fprintf(fr,"Number of words: %d\n",HOW);
	 return 0;
}
Prabakar 77 Posting Whiz

I guess Sliding Snakes of the desert can solve your problem.

Prabakar 77 Posting Whiz

Oh! I was out to lunch & I didnt see the replies you recived. Ya Its the same point.

Prabakar 77 Posting Whiz

fread& fwrite are used when, reading files in binary mode I presume. try using fgets(), fputs or open the file in binary mode & reply with what you have.

sizeof ( Recvbuff ) is always 22610. You cant assure that. Use the value returned by readfrom insted.

Prabakar 77 Posting Whiz

soory, I'll read 1/2 hour later. Got to go.

Prabakar 77 Posting Whiz

char *pop( ) { return items[top--] } ;
This is what I ment, & you code, compiled & executed well.

Prabakar 77 Posting Whiz

oops! sorry, wrong thread

Prabakar 77 Posting Whiz

items should be an array of pointers, in this program, the chars are stored in item & not the pointers,

char *items[10] ; should be used & in push just save, items[top++] = c;
& similarly change, the pop()

And also, fns defined inside main?

Prabakar 77 Posting Whiz

Well It took me about 40 minutes to code & 30 to analyse. Semester exams are going but, 70 minutes can be spared!

Prabakar 77 Posting Whiz

i think this is an example of "obfuscated code"

perl programmers also love to do stuff like this.

I copied the concept and wrote one on my own. here it is.

#include<stdio.h>

int main ()
{
	int a , b = 0, c = 10 ;
	for ( ; a = "ECEEBDEEBDBBBDBDEB0\
			BBBBBBBBBBBBBBBBBBBBBABCBBBBBBH0\
			CFBFBFBFBDDFBI0\
			FBABCBBBBBBBBBBBBBABCBBBBBABB0\
			BFBBBBBBBBECBBBBBBBBBBBBBBC"[b++] ; ) 
		for ( ; --a > 63 ; )
			putchar ( ++c == 73? c-=63 : 32^b&1 ) ;
	return 0 ;
}
Prabakar 77 Posting Whiz

That should make sence.
Well then have a nice day

Prabakar 77 Posting Whiz

Then you cant possibly expect help. And also, I over looked the code before.
>>char three (int, int char, double);
what is 'int char'?

Prabakar 77 Posting Whiz

test ( 5, 5, 7.3, 'z' ) will work.
And, What is your question?
>>I need a statement for the function test

what statements?

Prabakar 77 Posting Whiz

Sorry, Cause I want to annoy you with the same question.

<hbr> does not have an ending tag.
<I>, <a>, <body> tags needs or may have attributes.

if you are checking the beginning tag & ending tag, how will you handle this?

Sorry, If my question irritates you

Prabakar 77 Posting Whiz

Try, this one

// fn compare
int compare (const void * a, const void * b)
{ 
   return(strcmp(((Info*)a)->lastName,((Info*)b)->lastName ));
}

// in main function
case 3:
{
    qsort ( student, 5, sizeof( Info ), compare ) ;
}

also it would be better if you use switch case than if else structure
Dont, use so much spaces in your output iomanip offers a better way of doing it.

Edit:
And finally,
case 4 is a mess. sort it out.
Use code tags & intend it. Its difficult to read.

Prabakar 77 Posting Whiz

Teasing questions right.
What is the output of this.

#include<stdio.h>

int main ()
{
printf ( "%f", 10 ) ;
return 0 ;
}

Prabakar 77 Posting Whiz

The program is not that cryptic after all.
This guy has fooled me.
I understand what the He's been doing.

And this is what I found.

1. Ascii value of ' ' is 32 & that of ! is 33.
2. c varies from 10 to 90 - totaly 80 ( no of rows in the consol )
3. Ascii value of new line is 10.
4. b & 1 will return 1 or 0. i.e., ! or ' '
5. value of a is the number of ' ' & no of !

I cant belive I wasted 30 minutes in it.

Hope you guys agree with me.

Prabakar 77 Posting Whiz

qsort() is a good friend, as far as you know how to talk with him
I hope you like the code below

#include <iostream.h>
#include <string.h>
#include<stdlib.h>
struct values{
	char c[20], d[20] ;
} v[3] = { "a", "z", "b", "y", "c", "x" };

int compare (const void * a, const void * b)
{
  return ( strcmp ( (char *)a+20 , (char *)b+20 ));
}

int main ()
{
  int n ;
  qsort (v, 3, sizeof(values), compare);
  for (n=0; n<3; n++)
     cout << v[n].c << " "<< v[n].d;
  return 0;
}

One correction. In line 10
return ( strcmp ( ((values *)a)->d, ((values *)b)->d ) ; will be better.

Prabakar 77 Posting Whiz

If, you are using Visual c++, then goto Project-> settings and then to the debug tab. There in the arguments, text box type your commandline arguments, If not visual c++, then search for argument text box. There will be one some where.

or if you are running in console
<pgm-name> arg1 arg2
will work.

Prabakar 77 Posting Whiz

how do i fix this then so that the functions that i declared work properly

Actually, I thought, some code will be added, and didnt probe into details.

I dont know, what you want to do with the data you get from the user & the objects you've declared. Explain it a little more

Prabakar 77 Posting Whiz

I dont have much code to deal with, besides the constructor displays a '*' if mat element is 1 & the invert function does the same, even though it changes the matrix. Upload more code

Prabakar 77 Posting Whiz

Its a simple mistake.
if (grid[r][c] = 1)

= is an assinment operator. == is the relational operator

The code is just fine

Prabakar 77 Posting Whiz

qsort() is a good friend, as far as you know how to talk with him
I hope you like the code below

#include <iostream.h>
#include <string.h>
#include<stdlib.h>
struct values{
	char c[20], d[20] ;
} v[3] = { "a", "z", "b", "y", "c", "x" };

int compare (const void * a, const void * b)
{
  return ( strcmp ( (char *)a+20 , (char *)b+20 ));
}

int main ()
{
  int n ;
  qsort (v, 3, sizeof(values), compare);
  for (n=0; n<3; n++)
     cout << v[n].c << " "<< v[n].d;
  return 0;
}
Prabakar 77 Posting Whiz

if(student.lastName>student[i+1].lastName) { string temp; temp=student.lastName; student.lastName=student[i+1].lastName; student[i+1].lastName=temp; }

lastName is a char array. It wont help you sort this way.
use strcmp() to compare or using string class for names.

second, there is no use swaping just the last name, the purpose of your structure gets defeated by that.
You must thank c++ complier, cause it adds default copy constructor and assignment operator function to you class. just swap the entire structure

Prabakar 77 Posting Whiz

Its almost right.
line 28: cout << &credit
whats the use of printing the variables address

Prabakar 77 Posting Whiz

All I know in socket programing, is TCP/UDP echo program. so, I dont think I can help you with this.

And I dont understand, your reply too. why should you not be able to read .txt files from client. Is it because you dont know the nature of the file being transmitted by the client ?

Prabakar 77 Posting Whiz

I tried, to copy a word file within my computer(not socket program) and it worked.

Prabakar 77 Posting Whiz

I dont know sokcet programing. but I do know that word, can open txt files, so a simple way would be to open the file using .doc extention & in text format, write to the file & close it. It should work.

I guess, I mis understood. If you are reading, a word doc & saving it, then it sould work with binary mode. Perhaps, your client, doesnt have the latest version & lack upward compatibility. This may be a reson. And this is just a guess

Prabakar 77 Posting Whiz

I agree with that, printed to stdout & scaning from stdin. your code is wrong & I guess, you have not yet learned pointers. So, I would use arrays hear

declare char c[30] ;
in the loop, put c[i++] = rem ;
then in another while loop
while ( i ) putchar ( c ;

Prabakar 77 Posting Whiz

C++ is intersting, Isnt it I am learning it too, I still have to learn, templates, error handling, and so on. The book I read, says I still got a lot more to learn. All the best to you too.

Prabakar 77 Posting Whiz

I am new to forums too, as far as I can see, You can edit you post right after you post a message.

Prabakar 77 Posting Whiz

Using String would be better.

Prabakar 77 Posting Whiz

in decimal to binary, calcuation is ok. you are priinting binary number in reverse order

Prabakar 77 Posting Whiz

I dont understand your reply.

print the fname & show me what it prints