rahul8590 71 Posting Whiz

i have a csv file from where in i read the data and store individual coloumns in list , but for the last coloumn i am getting \n in the list . i want to get rid of that .

f = open('datagen.txt')
  for lines in f:
      line = lines.split(',')
      l1.append(line[0])
      l2.append(line[1])

l2 contains like abcd\n in it .. i dont want the newline character .

rahul8590 71 Posting Whiz

ohh totally forgot about that . thanks

rahul8590 71 Posting Whiz

The program is fetching me the right output but still i am getting a warning

#include<stdio.h>
#include<string.h>
int main()
{
char *p,*q;
p=(char *)malloc(25);
q=(char*) malloc(25);
strcpy(p,"hello" );
strcpy(q,"hi");
strcat(p,q);
printf("%s",p);
}

Warning
test7.c: In function ‘main’:
test7.c:6: warning: incompatible implicit declaration of built-in function ‘malloc’

wat exactly is the problem ?

rahul8590 71 Posting Whiz

no it doesnt ..

rahul8590 71 Posting Whiz
#include <stdio.h>
  #include <unistd.h>
  int main()
  {
          while(1)
          {
                  fprintf(stdout,"hello-out");
                  fprintf(stderr,"hello-err");
                  sleep(1);
          }
          return 0;
  }

why is that i am getting heelo-err instead of hello-out

rahul8590 71 Posting Whiz

Honeslty have no idea on how is the output being generated ?

#include <iostream>

int main(int argc, char** argv)
{
	int i=1,j=-1,k=0,l=2,m;  
	m=i++||j++&&k++;  
	printf("%d %d %d %d %d",i,j,k,l,m); 
	return 0;
}

output : 2 -1 0 2 1 evwn though j++ is is present that value is not being incremented

rahul8590 71 Posting Whiz

i have written many programs using stack , but how do i write a program to find whether the stack is progressing in forward or reverse direction . ?

rahul8590 71 Posting Whiz

http://www.daniweb.com/forums/thread305436.html


accidentally i posted in the wrong forum.

rahul8590 71 Posting Whiz

k guys . i do apologies that i posted in wrong forum . i guess you would have known that i am a total newbie to VB . i am not able to get the query right . it will e of great help if i can get string matching happen so i can fetch the corresponding data .

rahul8590 71 Posting Whiz

I have a search a particular filename in my msaccess file .
if i search through ID no , i am able to fetch the output . but if i am searching by comparing filenames then i am getting error

Private Sub cmdSearch_Click()
    Dim key As String, str As String
    key = InputBox("Enter the Employee No whose details u want to know: ")
    Set rs = Nothing
    str = "select * from emp where Filename=  &key "   // my search query is          //giving problems 
    rs.Open str, adoconn, adOpenForwardOnly, adLockReadOnly
    txtNo.Text = rs(0)
    txtName.Text = rs(1)
    txtCity.Text = rs(2)
    Set rs = Nothing
    str = "select * from emp"
    rs.Open str, adoconn, adOpenDynamic, adLockPessimistic
End Sub
rahul8590 71 Posting Whiz

well while executing u just write

$ time python program.py

"program output "

that time is printed in the end ....

==========================================

is that the incorrect way to check time for execution ?

rahul8590 71 Posting Whiz

how to interpret the time command .....

i executed a python program using time command as prefix during execution
and fetched this as output

real 0m7.741s real time is almost the same as user time
user 0m7.440s
sys 0m0.008s

But when i tried optimising ( algorithmically ) my python program i fetched another output

real 0m4.419s // the real time is way lesser than user time
user 0m7.660s
sys 0m0.052s


Well how do i decide which one of my implementation is better ,,,... does it depend on real time or user time .. ?

rahul8590 71 Posting Whiz
>>> while i < len(l1):
...  s = l1[i]
...  if s[0] not in d1:
...    d1[s[0]] = s[1]
...  else:
...    d1[s[0]] += 1
...  i = i + 1
... 
>>> d1
{}

geting empty dictionary .. :(

rahul8590 71 Posting Whiz

@jenzilla:

I dont know how far will this help you , but there is a module called easygui which is really very very easy to use , your question can be done soo easily

from easygui import *
name =  enterbox (" Welcome user , please enter your name " , "My APP ")
msgbox("Hello" + str(name) + " \n Press ok to quit" )
rahul8590 71 Posting Whiz

@tonyjv:

Both of our codes have a bug...... unquestionably ur method is the shortest ... i felt like a moron when i saw that conversions implicitly existed , but foe example

>>> l1
[('the', 1), ('quick', 1), ('brown', 1), ('fox', 1), ('jumped', 1), ('over', 1), ('the', 1), ('lazy', 1), ('grey', 1), ('dogs', 1)]
>>> d1 = dict(l1)
>>> d1
{'brown': 1, 'lazy': 1, 'jumped': 1, 'over': 1, 'fox': 1, 'grey': 1, 'quick': 1, 'the': 1, 'dogs': 1}

you see , although the pair (the , 1 ) repeats twice in the list , the dictionay accepts it only once and rather than updating the d = 2 it ignores the second occurrence. Even my initial code gives the same result :(


i tried writing this way .. but dunno why it isnt working

>>> while i < len(l1):
...  s = l1[i]
...  if s not in d1.keys():
...    d1[s[0]] = s[1]
...  else:
...    d1[s[0]] += 1
...  i = i + 1
... 
>>> d1
{'brown': 1, 'lazy': 1, 'jumped': 1, 'over': 1, 'fox': 1, 'grey': 1, 'quick': 1, 'the': 1, 'dogs': 1}

@woooee and @beat_slayer : i am working on your code ( thanks for providing one ).

rahul8590 71 Posting Whiz

@woooee:

the 1st part i have coded ,and converted the list to dictionaries

>>> l
[('a', 0), ('c', 2), ('b', 1), ('e', 4), ('d', 3)]
>>> dd= {}
>>> i = 0
>>> while i < len(l):
...  s = l[i]
...  dd[s[0]] = s[1]
...  i = i + 1
... 
>>> dd
{'a': 0, 'c': 2, 'b': 1, 'e': 4, 'd': 3}

now , if i get different dictionaries of different lengths from different files , how do i merge them . is there any direct module of doing so ?

rahul8590 71 Posting Whiz

@Beat_slayer

well .. the complete picture is i am implementing MapReduce framework .. i didnt find ne ( in python ) for me so decided to code by myself , i have come as far as writting mapper function and got stuck up in this list to dictionary conversion ..

For simplicity purpose i have mentioned 2 files here .. the actual thing will have more than 100 files and size of each file to be approximately around 5mb ( pure text only) and then run the mapper and reduce function in a multi threaded environment .. thats wat is the plan as of now .

@woooee : ur link is very helpful

rahul8590 71 Posting Whiz

I have various list being generated by a mapper function in this format


>>> mapper("b.txt" , i["b.txt"])
[('thats', 1), ('one', 1), ('small', 1), ('step', 1), ('for', 1), ('a', 1), ('man', 1), ('one', 1), ('giant', 1), ('leap', 1), ('for', 1), ('mankind', 1)]


>>> mapper("c.txt" , i["b.txt"])
[('thats', 1), ('one', 1), ('small', 1), ('step', 1), ('for', 1), ('a', 1), ('man', 1), ('one', 1), ('giant', 1), ('leap', 1), ('for', 1), ('mankind', 1)]


i want to merge the list generated from these 2 functions in a way that if i encounter a common element , then in the augmented list the data to be stored should be
('for' , 2) ( in this case , since for is common in both the results of mapper function) and the rest unique elements to be stored in augmented list as it is ..

PS: mapper function is a self made function

rahul8590 71 Posting Whiz

i did go thru a google search and found some functions .. but those results where horrifying , i guess i am using a wrong method of finding time .

def test():
    "Stupid test function"
    L = []
    for i in range(100):
        L.append(i)

if __name__=='__main__':
    from timeit import Timer
    t = Timer("test()", "from __main__ import test")
    print t.timeit()

The time taken to execute or displayed was 21.0178511143

is thats true .. then is python that slow ...? cuz in C its a fraction of a second ...

rahul8590 71 Posting Whiz

Well i have a small code snippet which is a basic http server. Well its running fine , but i am unable to catch the feedback and store it in a log file of my own for further analysis.

code snippet : http://codepad.org/MppnYU9n

just in case wondering on how to run it

create a directory and then run the code , inside it . u can add many html pages in it and then while running the python program

$python webserver.py

in ur browser open http://localhost:8000/ ensure the html pages u append in the directory atleast has one page named index.html.that particular page gets displayed and in the ternminal u will get various feedbacks ,
when ur requesting a valid page in ur browser ( test.html in this case ) . the feedback is pretty clear i guess.


output:
localhost.localdomain - - [20/Jul/2010 14:34:34] "GET /test.html HTTP/1.1" 200 -


when the file doesnt exist then output is :
localhost.localdomain - - [20/Jul/2010 14:22:16] code 404, message File not found

these output are displayed in the terminal , i want to store them in a log file, but unable to do so .

rahul8590 71 Posting Whiz

firstly srry for late reply , for some reason i aint getting notification of reply for the threads i started in daniweb , dunno y.

that is an awesome link .. very helpful .

rahul8590 71 Posting Whiz

here is a basic example of wat i meant by dynamic
the below is a basic form meant ti generate the no of name fields as inputed

<form action="redirect_new.php" method="post">
Name: <input type="text" name="yourname" maxlength="150" /><br />
<input type="submit" value="Submit" style="margin-top: 10px;" />
<?php
$val = $_POST['yourname'];
setcookie("name",$val,time()+3600);

for ( $i = 1; $i <= $val ; $i++)
{
?>
<form action="redirect1.php" method="post">
Name: <?php echo $i ?>  <input type="text" name=<?php echo "\"yourname"."$i\""   ?> maxlength="150" /><br />
<?php

} 
?>
<input type="submit" value="Submit" style="margin-top: 10px;" />

the above is the equivalent php code . Now in this case since we dont know the number of name fields to be entered , how do i generate the xml data for this ?

rahul8590 71 Posting Whiz

that was great .. it really helped me . but supposedly the input is dynamic in nature . i mean if i dont know the number of name inputs , in that case how do i generate the xml data out of it.

rahul8590 71 Posting Whiz

I have a couple of input boxes where the user will be entering his/her data .
for example:

Name:-------------
Fathers name:-----------
mothers name:------------

when the user enters the data , i need the xml to be generated something like this

<family>
<name> users name </name>
<fname> fathers name </fname>
<mname> mothers name </mname>
</family>

rahul8590 71 Posting Whiz

firstly sorry for late reply , i didnt get any notification in my mail that someone has replied ( usually never happens ) .
I will try both the techniques , i appreciate both of you . for ur help.

rahul8590 71 Posting Whiz

Well i need to change my banner of the website alternatively , like once user experiences
the pic1 which would be incorporated in my CSS. But the point is i want that pic to change .
for example
when user 1st time logs in , he see pic1 as a banner and next time or for other user , he might see a different banner ex pic2 . so in a given set of pics pic1 , pic2 , pic3 as banners , the banner keeps changing .

well i am not able to think on how to proceed since the banner link is in my CSS . have no idea on how to collaborate CSS + PHP

rahul8590 71 Posting Whiz

thanks rajaranjan and vibhadevit , kudos to you for such solutions .
Well now i can insert it in one page itself , but i need that another page redirect1.php because i want to display things like Registration details .

i thought of using a cookie for that

$val = $_POST['yourname'];
setcookie("name",$val,time()+3600);

but i dont think this may panout , since many people would have disabled cookies which would be a problem later on .
the point is i want to pass these variable values to the next page or the current page if its possible in order to display the registration details (more like a summary)

rahul8590 71 Posting Whiz

Well this might sound a bit ridiculous , i request the user to enter the no of names field to be generated and then i am successfully able to generate , but dont know how to go about saving those many names in the name column of my db.

initial html page

<form action="redirect.php" method="post">
Name: <input type="text" name="yourname" maxlength="150" /><br />
<input type="submit" value="Submit" style="margin-top: 10px;" />

redirect.php page

$val = $_POST['yourname'];

for ( $i = 0; $i < $val ; $i++)
{
?>
<form action="redirect1.php" method="post">
Name: <?php echo $i+1 ?>  <input type="text" name="yourname[]" maxlength="150" /><br />
<?php

} 
?>
<input type="submit" value="Submit" style="margin-top: 10px;" />

well i thought i would print the various names entered in redirect1.php and save it in db , any other ingenious ideas are welcomed /

rahul8590 71 Posting Whiz

> except:: standard-complaint brower would normally be standard-compliant browser
Oops Spelling mistake

>blatant plug dont bite me freeware no $$ changes hands
using DevPHP from sourceforge, a php IDE that lets you toggle between the mozilla and IE rendering engines,
code scrap works for me

I aint have any idea of what your talking about , i would be glad if you could throw some light on it

rahul8590 71 Posting Whiz

got it .. i did a little bit of tweaking and i guess this works ...
i would be glad if you could test it .. just in case .

<?php
function detect_ie()
{
    if (isset($_SERVER['HTTP_USER_AGENT']) && 
    (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false))
        return true;
    else
        return false;
}
?>
Welcome to the site.


<?php  
if (detect_ie()) {  
echo "<script> alert('It seems, that you are using IE. Why not to switch to standard-complaint brower, like FireFox') </script>";
}
?>
rahul8590 71 Posting Whiz

I have written a small script in order to check the browser of the user and find that the code isnt working , even if i open the php page in IE its still outputting Mozilla

<?php
$browser =  $_SERVER['HTTP_USER_AGENT'] ;
echo  $browser. "\n\n";
?>

Output in Mozilla:
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6

Output in IE:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.2)

i aint have ne idea on whats wrong with the output .

rahul8590 71 Posting Whiz

u gotto search plugins for both the cms in order to suit your requirements .
There are community builders for joomla AFAIK , aint have much idea about drupal .

rahul8590 71 Posting Whiz

well that certainly worked , kudos to you .
but isnt that javascript which u have incorporated ? i guess so
secondly i printed the echo statement first and then the header function , i dont get why should it directly jump to header func when a echo statement is encountered before

rahul8590 71 Posting Whiz

i have a basic script where in i check if the content is inputted or not .
If the content is not present i redirect to the same page also echoing a statement that u have not entered any data , but the echo message is not being printed.

the below is redirect.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ?
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>

<form action="redirect.php" method="post">
Name: <input type="text" name="yourname" maxlength="150" /><br />
<input type="submit" value="Submit" style="margin-top: 10px;" />


</form>
</body>
</html>

the below is redirect.php

<?php

if (trim ($_POST['yourname']) == "")
{
	echo " u have not entered any data ";
	header ("Location: redirect.html");
	exit;
}

echo $_POST['yourname'];

?>
rahul8590 71 Posting Whiz

well are u using any kind of DB for backend ?
I guess so ... In that case firstly think of an elegant backend for your application first for example u could have
student id , name , score1 , score 2, score 3 , score 4 , total ;

in the front end u can use input boxes to accept the scores and name ,
the total field in the DB can be calculated as the sum of the 4 scores
Later u can generate reports , to show the highest , least avg scores and any kind of statistics ur hoping to see .

rahul8590 71 Posting Whiz

i would suggest to go through various fields of computer science were algorithms are extensivesly applied ( i.e almost all the fields ) find your area of interest in them and then find what has been done in that particular field
ie the scope , recent tech etc
Finally according to your caliber , select a topic and understand the current implementation of algorithm and then u jump into making your own ,in a better way.

Algorithms are not dependent on Programming languages , any language (almost ) can execute a particular algorithm , it all comes down to logic which u must develop in order to enhance existing algorithm.
later u can think of performance issues , if a particular language isnt as scalable as you wanted it to be.

rahul8590 71 Posting Whiz

well when ur accepting the string u could use cx or some register and keep incrementing it aslong as the user doesnt press enter .

rahul8590 71 Posting Whiz

>I vote for slackware. I really dream about the same thing as you ... I hope one day I will find that "big bag" full of free time and do:


well the problem is .. its very difficult to find tutorials on these arcane topics .. and this leads you to take such bold steps of venturing out on our own.
i would try on slackware.. but i guess its a pretty mature OS and one of the oldest , i was wondering if you could suggest some nascent ones.

rahul8590 71 Posting Whiz

http://www.linuxfromscratch.org/

that will get u started .

rahul8590 71 Posting Whiz

well , i did face a similar problem in openGL and used their apis glutBitMapCharacter to render the text and that solved the issue :)

rahul8590 71 Posting Whiz

not build appications .. your not getting my point .
I mean build the internals of operating system , like for example the kernel runs on its own scheduling algorithms , i would like to write my own .
Or tamper with the file system and change some internals .. well basically messing around with the internals of OS in order to understand it better .

rahul8590 71 Posting Whiz

lucid doesnt help you to build one AFAIK .
I want something which helps u to build one .. since i am frustrated with theortical concepts like

File systems , scheduling algorithms , the getty , controlling terminal and stuff and i guess the only way to comprehend them profoundly could be building one . (ofcourse not from scratch )
Gentoo is one of the option which kinda suits my requirements , but i am looking for more nascent ones where i can contribute too. :)

rahul8590 71 Posting Whiz

how can i write a program to calculate the median of matrix in file1 , and send the output to file2 .....????
can anyone help me please??!
=======

sarah u gotto show some effort of your own .
Please give it a shot and later if you having problems u can post it in here , that would embolden people to help you .

1. U have a file with matrix data in it
2. u must have a function to retrive data from a file and store it in matrix format
3. Calculate the median using the formula , (i guess it shouldnt be a trouble finading the formula)
4.the result matrix u found , store it in another file

for simplicity purpose i would suggest you to first accept the matrix at run time , calculate the median and then print thr result , later on u can enhance it by introducing file reading ..

rahul8590 71 Posting Whiz

well wat exactly are u talking about

1. Implement TCP/IP ? or establish server - Client using TCP/IP ?

richard stevens book on unix have socket programming in them , i guess that might help you

rahul8590 71 Posting Whiz

well firstly u gotto understand OS more profoundly . and that can happen only if u have built OS by scratch . that doesnt mean that u code an OS , but coalesce different parts of OS into one and have your own small model .

rahul8590 71 Posting Whiz

well i would suggest for you to go in for Qt + C++ .
well for text editor you do need somekind of GUI and QT can help you with that.
besides its also got a standard example of text editor which you can download and learn how its built.

rahul8590 71 Posting Whiz

well all u gotto do , is to check the age of two people and print in the format asked
for example:

if (  x.age > y.age)
    cout<<x.name<<"is older than <<y.name;
else if ( x.age == y.age)
    cout<<x.name<<"is same age as "<<y.name;

well i am assuming ur doing using classes , it would be easier since the person will
share the same attributes so better to put in one class.

rahul8590 71 Posting Whiz

well just making an ecyption system based on existing cipher is like re inventing the wheel , so it would be better to innovate something at thesis level . well thats my speculation

rahul8590 71 Posting Whiz

DargonFire SDK ... hmmm thats not something which i have worked on before .
Well sometimes its not just the c++ coding but also the SDK taking control of the screen. I am not sure of that , but i can tell you out of my experience with openGL .
well i am sure that DF SDK will also have some APIs for displaying text . It would be prudent to use those APIs for rendering text rather than cout statements .

rahul8590 71 Posting Whiz

>If that isn't possible than I'll just forget it.
Well certainly thats possible .

well i dont know how your game is designed , but i faced an analogus problem in the past , where in the data was actually being printed , but i was also coming out of program immediate which made me unable to see the output.
so , i guess if you could ask the user to hit enter ( or any other character ) to exit the game or something similar , ur last output will still stay on the screen.

tiger86 commented: Very nice and helpful. +3