techie1991 26 Junior Poster in Training

Can someone please direct me to the code for the class <int> in python. I know that it must have written in C, but I could not understand, where to ask this query.
Though I tried to figure it out myself, but could not even understand, which folder to attack in the source code. (the source has really got some good great number of files..)

techie1991 26 Junior Poster in Training

I believe, you don't need a forum, but some books to study from...
Hope the following links help:
thread1
python books

techie1991 26 Junior Poster in Training

Thank you all, most of my questions have been sought by your answers... Now, the only thing left in doubt is the data space acquired..

char str1="";
char* str2=NULL;

see the link below:
codepad
Hope I am able to explain my problem..

techie1991 26 Junior Poster in Training

I believe your above comparison

#
for( size_t n = 0; myStr[n]!=NULL; n++)
#
(

would return an error code (as it is doing with me).
Check it at codepad This is what I was trying to point, the NULL character ('\0') and NULL are different (maybe!!)

techie1991 26 Junior Poster in Training

I was having some confusions about string and NULLs. So, I read this thread on this very forum. But, I could not understand somethings...
Firstly, Is NULL an integer value 0, or something else?
Secondly,

if(strlen(str)==0)

this shows that the string is null or it shows that the first character is '\0' ?
if I assign

str[]=""

str now is a null string or has no value or contains the null character '\0' or something else ? How much space is it going to acquire?
And finally, please suggest me some good and valid methods to check for NULLs in strings using C++..

techie1991 26 Junior Poster in Training

Can someone tell me the algorithm used by the functions sorted() and

  • .sort()?
techie1991 26 Junior Poster in Training

Can someone tell me the algorithm used by the functions sorted() and

  • .sort()?
techie1991 26 Junior Poster in Training

OK, thanks. now I understood. Actually I was trying to give it a key like:

c.sort(key=a['name'])
#OR
c.sort(key=['name'])

It actually didn't strike me that I should be using a lambda function.

techie1991 26 Junior Poster in Training

I want to sort a list of dictionaries using the inbuilt sort() function for lists. The problem is I am not able to understand, how to give the function a key..

Example:

a={'name':1,'data':200}
b={'name':2,'data':400}
c=[a,b]

Now, I want to sort the list c with the key being a. If i use c.sort(), it gives me an error as dictionaries can not be compared. Either I can use a sorting algorithm but that would make my program too complex.
So, can anyone suggest me a beeter approach.

techie1991 26 Junior Poster in Training

In your last reply, you gave a link to a question. I got a solution for it.

#include<iostream>
#include<conio.h>
using namespace std;
int main(){
    char a[15];
    gets(a);
    char b='1';
    for (int i=0;a[i]!='\0';i++){
        cout<<a[i];
        if ((a[i]!='1')&&(a[i]!='0')){
                                  b='2';
                                  break;
                                  }
        }
    b=='1'?(cout<<"It is binary...\n"):(cout<<"It is not binary...\n");
    getch();
    return 0;
    }

Even though I solved it but I am not quite happy with the solution as it takes a limited input. If I take a larger array, then I would be wasting memory space.
Rest all is correct I guess..?? :confused:

And to my question... It is also a question at spoj.pl
I will try to make that program too, pretty soon...

techie1991 26 Junior Poster in Training

I cannot use a imported library in this program.
So, is their no other way of getting a solution as I want.
I want to calculate sqrt(2) to the maximum level of digits possible...

techie1991 26 Junior Poster in Training

I was trying to make a program that gives very accurate answers to problems. The accuracy I want is of like 20000 terms.
For eg. 10/3 is written as 3.33333333333333333...20,000 times.
So, is it possible in Python?
The code I tried to get square root of 2 is:

import math
print(math.sqrt(2))

which gives:
1.4142135623730951... which does not fulfill my need.
Also, please answer in reference to Python 3.0, if possible...

techie1991 26 Junior Poster in Training

I was trying to make a program that gives very accurate answers to problems. The accuracy I want is of like 20000 terms.
For eg. 10/3 is written as 3.33333333333333333...20,000 times.
So, is it possible in Python?
Also, please answer in reference to Python 3.0, if possible...

techie1991 26 Junior Poster in Training

I want to print a float number with it's digits extending to 20000 digits after the decimal i.e. if the number is 10/3, it should print 3.333333333333333333333333333...20000 or more times.
So, how do I print something like that?
Also, do tell the solution for C and C++ as well...
The code I used was:

#include<iostream>
#include<math.h>
#include<conio.h>
using namespace std;
int main(){
    printf("%f",(sqrt(2)));
    getch();
    return 0;
    }

It gave me output: 1.414214

techie1991 26 Junior Poster in Training

Simply don't use .eof() in the loop control, it does not work as you may think it does. Rather do..

while (fr.read((char *) &s, sizeof s))
{
  printf(...);
}

Maybe see Why does my input seem to process past the end of file?

The above link and your explanation has solved my problem and I am very thankful to you for that.
But I am not able to understand that when I try to read from the file when the get pointer is at the last byte (or somwhere there) of the file then why does it read the last data element entry full. I meant that when the get pointer has already traversed the last entry then why is it travelling back a few bytes to read that again. Please explain???
And sorry for the late reply...

techie1991 26 Junior Poster in Training

Sorry, for the above problem. Actually, I was using a really slow connection and when I clicked the post reply button, it didn't work, so out of frustration i kicked it many times which led to the above seen problem.
But the reasons apart, seeing your reputations, i don't think that you should be giving such rude replies to anybody. And I was just trying to give a solution which a newbie (as written in the problem itself) could understand easily. I was just trying to give this site something back.
Still, as I am not of enough level to argue with you and i have really got my problems solved here, I would again apologise to you people (for all the reasons you are blaming me).

Ancient Dragon commented: Here's some rep back +26
techie1991 26 Junior Poster in Training

Though not of use to any of above repliers and solution seekers...
But if someone wants to shift from the old turbo C++ (yes, the one with the blue screen) can use the borland C++. It has the same basic structure as the old turbo C++, has most of the shortcuts intact and the best part is that it is free. I can't tell for the mingw and other graphic supports as i haven't used any of them on it (guess, you will have to find that yourself as i haven't learned it yet).

techie1991 26 Junior Poster in Training

Sorry, for the above way of posting. Actually, I didn't want to give a large code, so I gave just a small part of it.
Though, most of my problem was solved when you told that we can't access the same file from 2 pointers at the same time, and I am very thankful of you for your help. But, now I am having a new problem;
In the following code:

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<fstream.h>

struct dat{                     //This is the structure that I want to enter into my file
	int a,b;
};
int point=0;


 void read(){                                  //This whole function deals with reading
   	clrscr();                                  //data from file:"data.txt"
   	ifstream fr;

   	dat s;
   		fr.open("data.txt",ios::in,ios::beg);
   		while(fr.eof()==0){
   			fr.read((char *) &s, sizeof s);    //This is to read from the file, the data
   			printf("%d\t%d\n",s.a,s.b);
   		}
               fr.close();
   	getch();
   }

void insert(){                                   //This function inserts data in file
		dat v;
   	ofstream f;
   	clrscr();
   	if(point==0){                                   //I have used this if-else structure to see
	   	f.open("data.txt",ios::out);    //if the file is opened for first time. 
      	point=1;                                         //If the file is opened first time,
      	}                                                     //it opens it in out mode, else in append mode.
   	else{
   		f.open("data.txt",ios::app);
      	}
  		printf("Enter the data:\n");
  		cin>>v.b;
   	cout<<"\nData index number:"<<v.a<<"\nData value:"<<v.b<<"\n";
   	f.write((char*) &v, sizeof v);
   	v.a++;
   	f.close();
   	getch();
   	}

void main(){
insert();
read();
}

My aim is very simple. It is to input a structure in the file and then to read it back.
Now, the problem I am facing is that when I read the file, I am shown the value two times. And …

techie1991 26 Junior Poster in Training

@above repliers with all regards...Sorry to say, but you must keep in mind the level of person when answering...
The above solutions are using STL which come a way ahead in programming in C++
A more simple way is to:

ifstream f;
f.open("filename",ios::in);
char a[15];
while(!f.eof())
f>>a;

The above code reads from the file a word of max length 15 and puts it into the string "a". The line: f>>a, tells the compiler to read from file till a white space is encountered.
For more info, go to:
http://www.bgsu.edu/departments/compsci/docs/read.html

Fbody commented: spammer +0
jonsca commented: C'mon +0
techie1991 26 Junior Poster in Training

Sorry to say, but you must keep in mind the level of person when answering...
The above solutions are using STL which come a way ahead in programming in C++
A more simple way is to:

ifstream f;
f.open("filename",ios::in);
char a[15];
while(!f.eof())
f>>a;

hte above code reads from the file a word of max length 15 and puts it into the string a. The line: f>>a, tells the compiler to read from file till a white space is encountered.
For more info, go to:
http://www.bgsu.edu/departments/compsci/docs/read.html

techie1991 26 Junior Poster in Training

Sorry to say, but you must keep in mind the level of person when answering...
The above solutions are using STL which come a way ahead in programming in C++
A more simple way is to:

ifstream f;
f.open("filename",ios::in);
char a[15];
while(!f.eof())
f>>a;

hte above code reads from the file a word of max length 15 and puts it into the string a. The line: f>>a, tells the compiler to read from file till a white space is encountered.
For more info, go to:
http://www.bgsu.edu/departments/compsci/docs/read.html

techie1991 26 Junior Poster in Training

Hello, I was trying to implement data structures using file operations. I am using a data structure of two integers, one being the index number and other being the value. My actual aim is to recreate the file containing the data using a log. But, the program isn't running as required. Please help.
I am giving the code:

ifstream rlist;
   	rlist.open("redo.txt",ios::in);
   	ofstream datt;
   	datt.open("datatemp.txt",ios::out);
   	dat c;
   	char s;

   	while(!rlist.eof()){
         rlist>>s;
         if(s=='I'){
         		rlist.read((char*) &c,sizeof c);
            	datt.write((char*) &c,sizeof c);
               }
         if(s=='D'){
         		ifstream rlistd;
   				rlistd.open("datatemp.txt",ios::in);
               rlist.read((char*) &c,sizeof c);
            	ofstream rlistdw;
      			dat s;
               rlistdw.open("datatem.txt",ios::out);

   				while(!rlistd.eof()){
         			rlistd.read((char *) &s, sizeof s);
         			if((s.a)!=(c.a))
      					rlistdw.write((char*) &s, sizeof s);
                  }
      			rlistd.close();
      			rlistdw.close();
      			remove("datatemp.txt");
      			rename("datatem.txt","datatemp.txt");
      			}

Here, "redo.txt" is my log file. And dat is the structure name. The insert(s=='I') thing is working correct but there is some problem with delete one.
And is that true that we can't access the same file using two file pointers at the same time.
Waiting for reply...