C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 27th, 2012, 12:51 AM
lhon12006 lhon12006 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 56 lhon12006 Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 15 h 12 m 50 sec
Reputation Power: 0
Help compare substring

good day to all i have a problem in comparing my substring data

i am using sub string to synchronize my data in text file and plot it into another text file my problem is how can i compare my first sub string file to get the other data into separated department

sample data
computer hardware
001 mouse
002 monitor
007 keyboard

kitchen hardware
003 knife
004 scissors

substring(0, 20, buff, hardware, sizeof hardware);//hardware
substring(20, 24, buff, trace, sizeof trace);//trace code
substring(25, 50, buff, details, sizeof details);//details


PLEASE HELP ME!

Reply With Quote
  #2  
Old December 27th, 2012, 08:45 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,347 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 6 h 53 m 17 sec
Reputation Power: 383
I'm fighting too hard to understand the problem.

What is this substring function? c sharp? c++ string something?

What are buff, hardware, trace, and details ?

Synchonize?
Plot into another file?

Also, English may not be your first language. Please explain, more detail. Thanks.
__________________
[code]Code tags[/code] are essential for python code!

Reply With Quote
  #3  
Old December 27th, 2012, 08:14 PM
lhon12006 lhon12006 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 56 lhon12006 Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 15 h 12 m 50 sec
Reputation Power: 0
sorry sir i separate the textfile using substring then i want to compare it and organize the detail . how can i compare it to other ...
here is my file format
001computer hardwaremouse
002computer hardwaremonitor
003kitchen hardware knife
004kitchen hardware scissors
005kitchen hardware stove
006computer hardwarekeyboard
007computer hardwareplotter

and i want to organize it this form .... i compare all the data to organize it

computer hardware
001 mouse
002 monitor
007 keyboard

kitchen hardware
003 knife
004 scissors


thanks for your help sir "b49P23TIvg"

Reply With Quote
  #4  
Old December 27th, 2012, 09:29 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,347 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 6 h 53 m 17 sec
Reputation Power: 383
are there truly no spaces between
"hardware" and "mouse" ?

I'd like to know before I write a stupid program that works too hard to do the wrong thing.

Reply With Quote
  #5  
Old December 28th, 2012, 12:57 AM
lhon12006 lhon12006 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 56 lhon12006 Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 15 h 12 m 50 sec
Reputation Power: 0
[QUOTE=b49P23TIvg]are there truly no spaces between
"hardware" and "mouse" ?

yes sir so i use the substring

thanks again for the help sir
thank you so much

Reply With Quote
  #6  
Old December 28th, 2012, 09:24 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,347 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 6 h 53 m 17 sec
Reputation Power: 383
Code:
example='''001computer hardwaremouse
002computer hardwaremonitor
003kitchen hardware knife
004kitchen hardware scissors
005kitchen hardware stove
006computer hardwarekeyboard
007computer hardwareplotter
'''


'''
and i want to organize it this form .... i compare all the data to organize it

computer hardware
001 mouse
002 monitor
007 keyboard

kitchen hardware
003 knife
004 scissors
'''

import string,pdb

def arrange(data,feature):
    '''
        good enough to succeed with the test data, but not much better.
    '''
    d = dict()
    for line in data.split('\n'):
        fields = line.split(feature)
        if len(fields) < 2:               # the feature doesn't appear
            next
        key = fields[0].strip()
        value = feature.join(fields[1:]).strip() # handle multiple occurrences of feature, 1sFxFyFz -> 1s:xFyFz (still missing the endswith case, 1sFxF -> 1s:x  oh well
        d[key] = value
    bln = set()                     # extract 'kitchen' and 'computer'
    #    pdb.set_trace()
    for key in d.keys():
        for (i,c,) in enumerate(key):
            if c not in string.digits:
                break
        try:
            bln.add(key[i:])
            d[key] = key[:i]+' '+d[key]       # the values of d look like the innermost level
        except:
            del d[key]
    result = []
    a = result.append
    for n in sorted(bln):
        a(n+' '+feature)
        for (key,value,) in d.items():
            if n in key:
                a(value)
        a('')
    return '\n'.join(result)

def main(filename = None,feature='hardware'):
    try:
        with open(filename,'r') as inf:
            data = inf.read()
    except:
        data = example
    print(arrange(data,feature))

if '__main__' == __name__:
    main()
Comments on this post
lhon12006 agrees!

Reply With Quote
  #7  
Old December 28th, 2012, 09:23 PM
lhon12006 lhon12006 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 56 lhon12006 Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 15 h 12 m 50 sec
Reputation Power: 0
thank you so much this would be helpful for me ..

Reply With Quote
  #8  
Old December 28th, 2012, 11:41 PM
lhon12006 lhon12006 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 56 lhon12006 Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 15 h 12 m 50 sec
Reputation Power: 0
sir this is actually my code is
and it have a computation in the other data i substring


void Read(FILE *fin, FILE *fout){ ///// Sample REPORT
int num;
char buff[MAX_LEN +1];
while(!feof(fin)){
num = fread(buff, sizeof(char ), MAX_LEN, fin);
buff[num * sizeof(char )] = '\0';
if (strcmp(buff, "\0")!= 0){
substring(0, 2, buff, Num, sizeof Num);//Amt
substring(3, 20, buff, hardware, sizeof hardware);//Amt
substring(21, 30, buff, item, sizeof item);//Amt
if (strcmp(acct, hardware) != 0){
if (acct[0] == NULL) {
Head(); // print head
compute(); // print compute
}
else {
printf("\n\n");
SubHead();
}
strcpy(acct, AcctNo);
ctr++;
}
if (strcmp(acct, AcctNo) == 0){
if(strcmp(TranType, "1") == 0){ //// for transaction type
//for computation1
}
else{
for computation2
}
strcpy(acct, AcctNo);
}
fprintf(fptr1," %s%s%s \n",Num,hardware,item);
}
}
if (Fdata != '\0'){
1Foot(); // print footer
2foot();
}
else{
Head(); //print head
fprintf(fptr1, "\n\n\n\t\t NO DATA FOUND !!");
}
fclose(fin);
}

it is a pure C language sir my strcmp does not work to hard to find the compare
Comments on this post
salem disagrees: 30+ posts, and still no effing code tags!

Reply With Quote
  #9  
Old December 29th, 2012, 08:48 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,347 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 6 h 53 m 17 sec
Reputation Power: 383
oops. This is a c thread. Oh well, maybe the pseudo code is useful!

Reply With Quote
  #10  
Old January 3rd, 2013, 10:04 PM
lhon12006 lhon12006 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 56 lhon12006 Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 15 h 12 m 50 sec
Reputation Power: 0
Quote:
Originally Posted by b49P23TIvg
oops. This is a c thread. Oh well, maybe the pseudo code is useful!


thank you sir ...

Reply With Quote
  #11  
Old February 2nd, 2013, 12:33 AM
lhon12006 lhon12006 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 56 lhon12006 Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 15 h 12 m 50 sec
Reputation Power: 0
Quote:
Originally Posted by lhon12006
import string,pdb

def arrange(data,feature):
'''
good enough to succeed with the test data, but not much better.
'''
d = dict()
for line in data.split('\n'):
fields = line.split(feature)
if len(fields) < 2: # the feature doesn't appear
next
key = fields[0].strip()
value = feature.join(fields[1:]).strip() # handle multiple occurrences of feature, 1sFxFyFz -> 1s:xFyFz (still missing the endswith case, 1sFxF -> 1s:x oh well
d[key] = value
bln = set() # extract 'kitchen' and 'computer'
# pdb.set_trace()
for key in d.keys():
for (i,c,) in enumerate(key):
if c not in string.digits:
break
try:
bln.add(key[i:])
d[key] = key[:i]+' '+d[key] # the values of d look like the innermost level
except:
del d[key]
result = []
a = result.append
for n in sorted(bln):
a(n+' '+feature)
for (key,value,) in d.items():
if n in key:
a(value)
a('')
return '\n'.join(result)

def main(filename = None,feature='hardware'):
try:
with open(filename,'r') as inf:
data = inf.read()
except:
data = example
print(arrange(data,feature))

if '__main__' == __name__:
main().


sir can you create it in pure C language ..... thanks ...

Reply With Quote
  #12  
Old February 2nd, 2013, 11:32 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,347 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 6 h 53 m 17 sec
Reputation Power: 383
Writing this program is not fitting my priorities. I suggest writing a c code that links to the python.lib and using that interpreter, thereby calling it "pure c code". It is not wrong---indeed it is often good practice to implement a mini-language.

If I were to write the program for you I'd use flex and bison, and call it pure c code. Because it is, after flex and bison process these sources.

I could advise you that your statements
1Foot(); // print footer
2foot();
will not be meaningful to a c standard compliant compiler.

Reply With Quote
  #13  
Old February 8th, 2013, 02:05 AM
lhon12006 lhon12006 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 56 lhon12006 Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 15 h 12 m 50 sec
Reputation Power: 0
Quote:
Originally Posted by b49P23TIvg

I could advise you that your statements
1Foot(); // print footer
2foot();
will not be meaningful to a c standard compliant compiler.


sorry sir that foot means the "foot()"; method that print some details disregard the number in the first character of the method ...
thanks again sir for your help ..

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Help compare substring

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap