GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 30-Apr-2008, 10:16
faisalnet5 faisalnet5 is offline
New Member
 
Join Date: Feb 2008
Posts: 21
faisalnet5 is on a distinguished road

"Mapping algorithm" - Can anyone help me please ...???


My output File is having the following data:

"MFITRWLFSTNHKDIGTLYLLFGAWAGMVGTALSLLIRAELGQPGTLLG DDQIYNVIVTA
HAFVMIFFMVMPIMIGGFGNWLVPLMIGAPDMAFPRMNNMSFWLLPPSFL LLLASSTVEA
GAGTGWTVYPPLAGNLAHAGASVDLAIFSLHLAGVSSILGAINFITTIIN MKPPALTQYQ
TPLFVWSVMITAVLLLLSLPVLAAGITMLLTDRNLNTTFFDPAGGGDPIL YQHLFWFFGH
PEVYILILPGFGMISHIVTYYSGKKEPFGYMGMVWAMMSIGFLGFIVWAH HMFTVGLDVD
TRAYFTSATMIIAIPTGVKVFSWLATLHGGNIKWSPALLWALGFIFLFTI GGLTGIVLAN
SSLDIVLHDTYYVVAHFHYVLSMGAVFAIMGGFVHWFPLFTGYTLNDLWA KIHFSIMFVG
VNMTFFPQHFLGLSGMPRRYSDYPDAYTTWNIISSIGSFISLTAVILMVF IIWEAFASKR
EVATVELTTTNIEWLYGCPPPYHTFEQPVFVKV
MASTNTNLQKAIDLASKAAQEDKAGNYEEALQLYQHAVQYFLHVVKYEAQ GDKAKQSIRA
KCTEYLDRAEKLKEYLKKKEKKPQKPVKEEQSGPVDEKGNDSDGEAESDD PEKKKLQNQL
QGAIVIERPNVKWSDVAGLEGAKEALKEAVILPIKFPHLFTGKRTPWRGI LLFGPPGTGK
SYLAKAVATEANNSTFFSISSSDLVSKWLGESEKLVKNLFQLARENKPSI IFIDEIDSLC
GSRSENESEAARRIKTEFLVQMQGVGVDNDGILVLGATNIPWVLDSAIRR RFEKRIYIPL
PEAHARAAMFRLHLGSTQNSLTEADFQELGRKTDGYSGADISIIVRDALM QPVRKVQSAT
HFKKVRGPSRADPNCIVNDLLTPCSPGDPGAIEMTWMDVPGDKLLEPVVS MWDMLRSLSS
TKPTVNEQDLLKLKKFTEDFGQEG"

If u look carefully then u can see that there are two sequences. My code is as follows......what i am trying to do is, i already defined an array called: ngram [] = "FITRW".....when my code will run it should take my array and map with the first sequence.....if it gets any match then will print something and then after having done with the first one it will go to the second sequence and will do the same till my file ends....Can any one tell me in my code, where i am doing the mistake......Please help me....Regards !!!

CPP / C++ / C Code:
#include<stdio.h>
#include<conio.h>
#include<string.h>

int main (){

 FILE *open;
 
 char *pch;
 char pSequence[500];
 char ngram [] = "FITRW";
 
 open=fopen("output.txt", "r");
 
 while (fscanf(open, "%s", &pSequence) != EOF) {
       
       if (pSequence == '\0'){
                     
           printf("I am here\n");          
           pch = strstr(pSequence, ngram);
       
           while (pch != NULL)
           {
             printf("Found at %d\n", pch-pSequence+1);
             pch = strstr(pch+1, ngram);
           }
       }
       
 printf("\n%s", &pSequence);
 
 }
 
 return 0;   
    
}
----Faisal
  #2  
Old 30-Apr-2008, 11:50
L7Sqr L7Sqr is offline
Member
 
Join Date: Jul 2005
Location: constant limbo
Posts: 116
L7Sqr has a spectacular aura about

Re: "Mapping algorithm" - Can anyone help me please ...???


CPP / C++ / C Code:
char pSequence[500];
Could become
CPP / C++ / C Code:
char pSequence[500] = {0};
So you can be sure that you have null values in the array.
CPP / C++ / C Code:
if (pSequence == '\0')
can then become
CPP / C++ / C Code:
if (pSequence[0] != 0)
Also, fscanf returns the number of items assigned, so you may want to check for != 0, instead of != NULL
  #3  
Old 30-Apr-2008, 12:46
faisalnet5 faisalnet5 is offline
New Member
 
Join Date: Feb 2008
Posts: 21
faisalnet5 is on a distinguished road

Re: "Mapping algorithm" - Can anyone help me please ...???


Hi...L7Sqr....thanks a lot for ur reply. By the way i have done those changes which u did mention to me but then the output is coming as follows:

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

E:\BlackBox\CS Research\C-Coding\Software>map
MFITRWLFSTNHKDIGTLYLLFGAWAGMVGTALSLLIRAELGQPGTLLGD DQIYNVIVTA
Found at 2
HAFVMIFFMVMPIMIGGFGNWLVPLMIGAPDMAFPRMNNMSFWLLPPSFL LLLASSTVEA
GAGTGWTVYPPLAGNLAHAGASVDLAIFSLHLAGVSSILGAINFITTIIN MKPPALTQYQ
TPLFVWSVMITAVLLLLSLPVLAAGITMLLTDRNLNTTFFDPAGGGDPIL YQHLFWFFGH
PEVYILILPGFGMISHIVTYYSGKKEPFGYMGMVWAMMSIGFLGFIVWAH HMFTVGLDVD
TRAYFTSATMIIAIPTGVKVFSWLATLHGGNIKWSPALLWALGFIFLFTI GGLTGIVLAN
SSLDIVLHDTYYVVAHFHYVLSMGAVFAIMGGFVHWFPLFTGYTLNDLWA KIHFSIMFVG
VNMTFFPQHFLGLSGMPRRYSDYPDAYTTWNIISSIGSFISLTAVILMVF IIWEAFASKR
EVATVELTTTNIEWLYGCPPPYHTFEQPVFVKV
MASTNTNLQKAIDLASKAAQEDKAGNYEEALQLYQHAVQYFLHVVKYEAQ GDKAKQSIRA
KCTEYLDRAEKLKEYLKKKEKKPQKPVKEEQSGPVDEKGNDSDGEAESDD PEKKKLQNQL
QGAIVIERPNVKWSDVAGLEGAKEALKEAVILPIKFPHLFTGKRTPWRGI LLFGPPGTGK
SYLAKAVATEANNSTFFSISSSDLVSKWLGESEKLVKNLFQLARENKPSI IFIDEIDSLC
GSRSENESEAARRIKTEFLVQMQGVGVDNDGILVLGATNIPWVLDSAIRR RFEKRIYIPL
PEAHARAAMFRLHLGSTQNSLTEADFQELGRKTDGYSGADISIIVRDALM QPVRKVQSAT
HFKKVRGPSRADPNCIVNDLLTPCSPGDPGAIEMTWMDVPGDKLLEPVVS MWDMLRSLSS
TKPTVNEQDLLKLKKFTEDFGQEG
================================================== ====

If u see the output then will realize that it is just reading the lines, then whenever it is getting the first match then stoped.....and not implementing the mapping algo. to the rest of the sequences it is reading from the file.....

Any idea what to do?

-----> Faisal
  #4  
Old 30-Apr-2008, 14:14
L7Sqr L7Sqr is offline
Member
 
Join Date: Jul 2005
Location: constant limbo
Posts: 116
L7Sqr has a spectacular aura about

Re: "Mapping algorithm" - Can anyone help me please ...???


what mapping algorithm?
The string you are looking for only appears once within that file. You found it.
Your code says to print and then find the next one. If there is no next one, you exit the program.
  #5  
Old 30-Apr-2008, 14:52
faisalnet5 faisalnet5 is offline
New Member
 
Join Date: Feb 2008
Posts: 21
faisalnet5 is on a distinguished road

Re: "Mapping algorithm" - Can anyone help me please ...???


Do u know what.....i am totally SUCKS today......

Thanks a lot....u r right......!!! I am doing the right thing but saying it is wrong......What the........i really heat this bullshit programming life


Thanks again man.....it took my whole day.......!!!

God bless u....
  #6  
Old 06-May-2008, 17:29
Peter_APIIT Peter_APIIT is offline
Regular Member
 
Join Date: May 2007
Location: Malaysia
Posts: 425
Peter_APIIT is on a distinguished road

Re: "Mapping algorithm" - Can anyone help me please ...???


I don't understand where you got two sequences of the output.

Please explain.
__________________
Linux is the best OS in the world.
 
 

Recent GIDBlogToyota - 2008 August Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 05:07.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.