abhimanipal 91 Master Poster

When you declare some thing of the sort

int int1;

The compiler gives any arbitrary value to i. This could be 0,1,2,... any value what so ever.

As you input a char in response to the second cin, the compiler ignores the value entered by you.
Later when you want to display the entered value, the compiler prints the value of i, which will be garbage in your case

Run this code. If you give the input AZ, it will print A-1

int main()
{
 char ch1;
int int1=-1;
cin >> ch1;
cin >> int1;
cout << ch1 <<"\n";
cout << int1 << "\n";
      getch();
    return 0;
}

I hope this clears your confusion

abhimanipal 91 Master Poster

When we multiply 2 matrices, each element of the first row of the first matrix is multiplied with each element of the first column of the second matrix and so on
If you can bring one row of the first matrix and one column of the second matrix into the main memory, multiply them and store the result back to the disk, this might speed up the computation

abhimanipal 91 Master Poster

What is the size of the double pointer ?

abhimanipal 91 Master Poster

I want my code to take two characters and print them, but this code only takes one character, prints it and terminates, can you please tell me what's wrong with it? Thank you.

#include <stdio.h>
 int main()
 {
         char a, b;
         scanf("%c", &a);
         scanf("%c", &b);

         printf("%c %c\n", a,b);

         return 0;
 }

When you enter the first character you are actually entering 2 characters. The character itself and ('\n') when you hit the enter key. So both the scanf's get satisfied. The solution is to use fgets as suggested above

abhimanipal 91 Master Poster

time is a key word. So the compiler is not allowing you to call the print time function. Change the name of the object from time to time_1 and then try

abhimanipal 91 Master Poster

I am not sure if this will help but
Could it be the case that the int that you are passing to the sleep function is 2 big (the value has over flown )

abhimanipal 91 Master Poster

I am sorry but this is an interview question. I do not plan to use it anywhere..:)
This code calls the function just once. I used a cout statement to check this
How exactly is the overloaded () operator being called or where is it being called from ?

abhimanipal 91 Master Poster

Hello Everybody,
Most of my coding experience is in C. Although I have a background in C++, I know very little of STL and the advanced topics in C++.
I came across this code

struct g
{
	g():n(0)
    {
    }
	int operator()() { return n++; }
	int n;
};

int main()
{
	int a[10];
	std::generate(a, a+10, g());
	std::copy(a, a+10, std::ostream_iterator<int>(std::cout, " "));
	getch();
	return 0;
}

The output that I get is 0 1 2 3 4 5 6 7 8 9
Now this is my under standing of what is happening. The generate function calls the function g(). This function first assign n the value of 0
What I am unable to understand is how and where is the overloaded () operator called ? And how does it get called 10 times when the function g() is just called once.

abhimanipal 91 Master Poster

Quick question... How are you supposed to edit the test ?

abhimanipal 91 Master Poster

Your problem is that in the convertToPostfix function your are returning a null stack. Print out the content of the top of the stack just before you return it . The content prints out to be -1 . Consequently in the eval function when you check to see if the stack is empty, this return true and your code does not enter the while loop

abhimanipal 91 Master Poster

Use an enum. Define all the 13 cards in the enum

enum card
{
   one=1,
   two=2,

   ......
   jack=11,
   queen=12
};
abhimanipal 91 Master Poster

Why is the username and password integer datatypes ?
Why have you used cprintf ?
Syntax of fwrite is wrong

abhimanipal 91 Master Poster

Google for getch()/ cin.get()
Put it before the last cout

abhimanipal 91 Master Poster

Where are you getting the crash ? I ran the same code and I got the correct output. This is my output

abcdefghijklmnopqrstuvwxyz
ajluz
0bcdefghi0k0mnopqrst0vwxy0
bcdefghikmnopqrstvwxy

Did you put a getch() after the last cout ?

abhimanipal 91 Master Poster

You can do something of this sort

class test
{
      int x;
public:
  
     void getNum();
      void printNum();
};

void test::getNum()
{
   // You do not have to pass any parameters to this function. This is a member function of the class hence it can access all the members of the class  
    cout<<"Enter x\n";
    cin>>x;
}

void test::printNum()
{
 // You do not have to pass any parameters to this function. This is a member function of the class hence it can access all the members of the class  
     cout<<x;
}

For each object the member function can access all the data members of the class

abhimanipal 91 Master Poster

One solution could be to replace the '0' by ' ' ie the space character. Is this allowed ?
Make a temp array and run a for loop over the alpha array and each time the character is not a (0 or ' ') copy it to the temp array.

abhimanipal 91 Master Poster

Quick question. Have you ever included files before ? If no then I think
for some reason the header files in the main class are not getting included. That is why, when you call the constructor of the classes defined in those files you are getting an error.

abhimanipal 91 Master Poster

You do not need to make different functions for each object. Also your print function is wrong
Read up the concepts of objects one more time and you will see that you just need one getter / setter methods per class

PS: Change your void main to int main

abhimanipal 91 Master Poster

If after resolving the memory issue you are still getting file not found, I will suggest that you take the full path name of the directory

abhimanipal 91 Master Poster

Is it some thing of this sort ?
Multiply all numbers from 1- n with the number 2 ?
If this is it then a simple while loop will suffice

abhimanipal 91 Master Poster

Some suggestions
1. Print the contents that you read from the files. In line 133
2. Why are you not considering the value returned by the searchList function- Line 135
3. Also when you call the insert function. What parameters are you sending into the function
4. Google for "insert a node in a lined list"

abhimanipal 91 Master Poster

Can you explain the context of the problem ?

abhimanipal 91 Master Poster

You are passing the arrays by value. The changes made to these arrays will be local to the function.
Pass by pointer or use global variables

Dave Sinkula commented: Arrays can't be passed by value the way you imply. -2
abhimanipal 91 Master Poster

No you don't. What you have is an array of 4 bytes -- one character = one byte.

Right so you can store 1 byte in each character

abhimanipal 91 Master Poster

If you are having trouble getting started, think on the lines of linked lists. Store each number in 1 node of a linked list. So now the size of the number is not a criterion any more.
So for adding just scan both the lists and store the result in the third list. Take care of the carry though

Ancient Dragon commented: Linked list -- good suggestion :) +26
abhimanipal 91 Master Poster

If you have an array of 4 characters, then you have 32 bytes...
Will this work for your application ?

abhimanipal 91 Master Poster

On the while loop in line 51,there are no brackets. Change that. Use the return value from malloc to see if you got the desired memory or not ?
Instead of using pointer to pointer, you could try using an array of pointers. The advantage being an array of pointers is slightly easier to manipulate.

abhimanipal 91 Master Poster

E. Balaguruswami is not a good author. I was reading his C++ book and it has many mistakes. Most notably the use of void main all over the place
I would recommend, Let us C, by Yashwant Kanitkar

abhimanipal 91 Master Poster

One suggestion is to remove the data declarations from line 47-48 and put then at the beginning of the function.
In C all data declarations have to be at the beginning of the function

Put some printfs in your code, narrow down the area where you are getting the problem. Then post again on the forum

abhimanipal 91 Master Poster

You might want to try the function

gettimeoftheday()

PS I am not sure of the arguments

Dave Sinkula commented: Hey! Wow! This post is almost entirely useless! -2
abhimanipal 91 Master Poster

Try setting

hold[0] = '\0';

Or you may try using buffer[0] == '|'

buffer[0] means *(buffer + 0) which can be simplified as *(buffer)
This is obviously same as *buffer

abhimanipal 91 Master Poster

For printing the string the normal way (unreversed) you can use

printf("%s\n,name_of_string)

WaltP commented: And how does this comment help with printing the string backwards? -2
abhimanipal 91 Master Poster

fork system call returns the process id of the child and parent. You could use this information

abhimanipal 91 Master Poster

Also I would advise clearing out the contents of array1 and array2. As these arrays are local variables they will contain junk values and this could affect your out put

abhimanipal 91 Master Poster

Why are you not executing the cd command via excec ?

abhimanipal 91 Master Poster

Hello everyone i am new in C language and need some basic help.

see this program,

void main(void)
{
int a,b;
clrscr ();
{
for (a=1;a<5;a++)
{
for (b=2;b<6;b++)
{
printf ("value of a is %d , value of b is %d \n",a,b);
b=a+1;
a=a++;
}
}
}
getch();
}

i've used 'for' loops in this program and i am getting this output.

value of a is 1, value of b is 2
value of a is 2, value of b is 3
value of a is 3, value of b is 4
value of a is 4, value of b is 5

and it is perfectly fine.

Are you sure this the O/P that you are getting, I ran the code and I got an infinite loop at
a=1, b=3

The statement b=a+1 make the value of b 2 and then because of the for loop, b becomes 3. Then again 2 then again 3 and so on


but i want to know that why i need to increment the value of a again since i've already incremented it in this statement

{
for (a=1;a<5;a++)
{

why i need to increment it again after printf function ?
why it is not working if i am not incrementing it again ?


2nd question:

see this program,

void main(void)
{
int a,b;
clrscr ();
a=0, b=2;
while (a<1)
{
while (b<7)
{
printf ("a is %d, b is %d\n",a,b);
b=b+2;
}
a=a+1;
}
getch (); …
abhimanipal 91 Master Poster

Quick question were you looking for a mathematical solution or a programming kinda solution like the one described above ?

abhimanipal 91 Master Poster

Just take any one skill and become the master of that

abhimanipal 91 Master Poster
abhimanipal 91 Master Poster

In the main function you call print on line 107.. Before that can you print the entire array of structs ??

abhimanipal 91 Master Poster

You could use exit as well.
But for this situation it is more appropriate to use the suggestions mentioned above

abhimanipal 91 Master Poster

One method could be to store all the input numbers in an array.
Then find the max and min of this array. If you google you might even get the code for these functions.

Your current approach is quite complicated. You dont need so much complication

abhimanipal 91 Master Poster

Some thing of this sort

struct test
{
     int x;
}t1;

t1.x=20
abhimanipal 91 Master Poster

Happy Holi to you also

abhimanipal 91 Master Poster

Or you can make n as a global variable
Max can be calculated in the function as well

abhimanipal 91 Master Poster

Does this problem persist across all the sorting algorithms or just for merge sort ?

abhimanipal 91 Master Poster

What kind of error are you getting ?

abhimanipal 91 Master Poster

This might get you started.
There are 2 string: stringA= hellow , stringB= owl

So what you got to do is take the first character of string B and iterate it over stringA from the ending. In this case, we take the character o from stringB and compare it with w
It does not match so move ahead to o. This one does match. So now you compare the 2 character of stringB that is w

Did you get the logic ?

abhimanipal 91 Master Poster

I am not sure if this will help, but could you over write the data you want to be removed, with spaces ?

Ancient Dragon commented: my thoughts too +26
abhimanipal 91 Master Poster

You could use the division operator to convert marks from 1-100 range to 1-10. Then you just have to write 10 switch cases