Help need for programming link list in DeV c++..

  • (6 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • Last »

80 Replies - 9625 Views - Last Post: 17 July 2012 - 11:25 AM Rate Topic: **--- 3 Votes

#16 RRITESH   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 30
  • Joined: 02-May 12

Re: Help need for programming link list in DeV c++..

Posted 03 May 2012 - 02:37 AM

View PostDimitriV, on 03 May 2012 - 02:25 AM, said:

Did that code work for you? I hope it did.
Is the issue resolved now?



Yes the code is working i have written it but now i want to make char compare program...!!
Was This Post Helpful? 0
  • +
  • -

#17 DimitriV   User is offline

  • vexing conundrum
  • member icon

Reputation: 587
  • View blog
  • Posts: 2,746
  • Joined: 24-July 11

Re: Help need for programming link list in DeV c++..

Posted 03 May 2012 - 02:44 AM

View PostRRITESH, on 03 May 2012 - 08:24 PM, said:

So, i was writing a code for comparing int number and returning output, it was working fine as i want to do.
but in top i don't understand the use of int main(), as typing void main() shows and error can we write char main()??

#include <iostream>

using namespace std;
 int main() {
     int a;
   cout << "hello world\n";
   cin>>a;
   if (a==2)
   cout<<"right";
   else
   cout<<"wrongh";

 }


but i want to compare char then what to do??

Depends how you want to!

What purpose is this comparison going to serve? What do you want to achieve here?
Was This Post Helpful? 1
  • +
  • -

#18 RRITESH   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 30
  • Joined: 02-May 12

Re: Help need for programming link list in DeV c++..

Posted 03 May 2012 - 02:52 AM

Actually i want to do simple comparison as i have done it in numeric number, here i will compare and write right and wrong if char matches!!
Was This Post Helpful? 0
  • +
  • -

#19 aresh   User is offline

  • It's a 16-Bit World!
  • member icon

Reputation: 273
  • View blog
  • Posts: 4,258
  • Joined: 08-January 12

Re: Help need for programming link list in DeV c++..

Posted 03 May 2012 - 03:00 AM

#include <iostream>
using namespace std;
 int main()
{
   char a;
   cout << "hello world\n";
   cin>>a;
   if (a=='2')
   cout<<"right";
   else
   cout<<"wrong";
}


By writing '2' instead of 2, we are telling the compiler that we are dealing with character 2, not a character having ASCII value 2. Similarly, write 'a' for checking a, '0' for checking 0 and so on.

This post has been edited by aresh: 03 May 2012 - 03:04 AM

Was This Post Helpful? 1
  • +
  • -

#20 RRITESH   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 30
  • Joined: 02-May 12

Re: Help need for programming link list in DeV c++..

Posted 03 May 2012 - 03:07 AM

I think you are not getting me i want to compare char not number or acsii value.
anyway why u are using '2'??
Was This Post Helpful? 0
  • +
  • -

#21 DimitriV   User is offline

  • vexing conundrum
  • member icon

Reputation: 587
  • View blog
  • Posts: 2,746
  • Joined: 24-July 11

Re: Help need for programming link list in DeV c++..

Posted 03 May 2012 - 03:11 AM

Char is an ASCII value!
Was This Post Helpful? 1
  • +
  • -

#22 RRITESH   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 30
  • Joined: 02-May 12

Re: Help need for programming link list in DeV c++..

Posted 03 May 2012 - 03:14 AM

View PostDimitriV, on 03 May 2012 - 03:11 AM, said:

Char is an ASCII value!


So, i have to write ASCII value for comparing can't i do with char directly??
Was This Post Helpful? 0
  • +
  • -

#23 aresh   User is offline

  • It's a 16-Bit World!
  • member icon

Reputation: 273
  • View blog
  • Posts: 4,258
  • Joined: 08-January 12

Re: Help need for programming link list in DeV c++..

Posted 03 May 2012 - 03:16 AM

Do you know what an ASCII value is ?? Please look it up first on Wikipedia. Here is the link http://en.wikipedia.org/wiki/ASCII . I have explained why I am using '2'... It is to tell the complier that we are comparing the character 2, not a character having ASCII value 2 !! Every character is interpreted by its ASCII value. 2 has the ASCII value 50. So, while comparing char, the complier actually compares their ASCII value. By writing 2, you are saying the character has ASCII value 2, which is not the case. Hence we are using '2'. If you don't want to write if(a=='2'), you can also write if(a==50), because 50 is the ASCII value of the character 2.

This post has been edited by aresh: 03 May 2012 - 03:17 AM

Was This Post Helpful? 1
  • +
  • -

#24 RRITESH   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 30
  • Joined: 02-May 12

Re: Help need for programming link list in DeV c++..

Posted 03 May 2012 - 03:17 AM

I think then also the above code is wrong if it is using AScII method!
Was This Post Helpful? 0
  • +
  • -

#25 aresh   User is offline

  • It's a 16-Bit World!
  • member icon

Reputation: 273
  • View blog
  • Posts: 4,258
  • Joined: 08-January 12

Re: Help need for programming link list in DeV c++..

Posted 03 May 2012 - 03:19 AM

In the above code, I have wrote '2', due to which it interprets it as a character 2, having ASCII value 50. That is why I have used ''. They are always used to represent a character.
Was This Post Helpful? 0
  • +
  • -

#26 RRITESH   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 30
  • Joined: 02-May 12

Re: Help need for programming link list in DeV c++..

Posted 03 May 2012 - 03:23 AM

Ok, i am getting you now..
please tell what is the function of using 'b'inverted comma ??
Was This Post Helpful? 0
  • +
  • -

#27 aresh   User is offline

  • It's a 16-Bit World!
  • member icon

Reputation: 273
  • View blog
  • Posts: 4,258
  • Joined: 08-January 12

Re: Help need for programming link list in DeV c++..

Posted 03 May 2012 - 03:26 AM

As far as I remember, b has an ASCII code 98. So if you want to compare a char with 'b', then you have to use 'b' so that the compiler interprets its ASCII value 98. If you don't use 'b' and simply write b, it will NEVER be true and hence either your compiler will give an error or if it doesn't, always the else statement will be executed. Always use '' while comparing characters, until and unless you prefer writing the ASCII code the character manually.

This post has been edited by aresh: 03 May 2012 - 03:28 AM

Was This Post Helpful? 1
  • +
  • -

#28 DimitriV   User is offline

  • vexing conundrum
  • member icon

Reputation: 587
  • View blog
  • Posts: 2,746
  • Joined: 24-July 11

Re: Help need for programming link list in DeV c++..

Posted 03 May 2012 - 03:26 AM

View PostRRITESH, on 03 May 2012 - 09:23 PM, said:

Ok, i am getting you now..
please tell what is the function of using 'b'inverted comma ??

Strings use double-quotes. Chars use single quotes. That way you can tell them apart. A char can also only hold one character.
Was This Post Helpful? 1
  • +
  • -

#29 RRITESH   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 30
  • Joined: 02-May 12

Re: Help need for programming link list in DeV c++..

Posted 03 May 2012 - 03:29 AM

OK OK, so I think now i should start single link list program..
please guide me to start it!!
Was This Post Helpful? 0
  • +
  • -

#30 aresh   User is offline

  • It's a 16-Bit World!
  • member icon

Reputation: 273
  • View blog
  • Posts: 4,258
  • Joined: 08-January 12

Re: Help need for programming link list in DeV c++..

Posted 03 May 2012 - 03:34 AM

By single link list, do you mean a singly linked list ??? If yes, then you will need to have knowledge about classes/structures and pointers. Do you know about them ??
Was This Post Helpful? 1
  • +
  • -

  • (6 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • Last »