## myth_terry -6

hello frns.. :icon_smile:

read strings from a text file "text1.txt" (which are stored 1 per line without spaces) and store these strings in a string array A[].
then read strings from one more file "text2.txt" and store it in another string array B[]
create a string array C[] which contains the strings from B[] but without duplication of strings.
read strings from another text file "text3.txt" and store it in a string array D[]
now create a string array E[] which contains all the strings from C[] but without strings which are also in D[]. i mean : E[] = C[] - D[].
now write all the strings in E[] to a file "text4.txt"

please i need it very urgently. This code is a back end for a part of the GUI of my project. i'm not good at programming with input/output of files.

thank u soo much...

-Mith

## gerard4143 371

Sounds like homework to me...Lets see what you have so far.

## myth_terry -6

Actually this is a part of my project.. I'm mostly working on visual basic. but this c part is troubling me. i am fine with C but the file I/O i feel a bit complicated. i write those file "text1.txt" "text2.txt" so on through VB.

OK let me explain u my project in brief

I access a database for the attributes of a particular table or tables.
Then i accept some functional dependencies from the user.

the user dependencies are of the form

{att_x_1, att_x_2,...} -> {att_y_1, att_y_2,....}

here
att_x are attributes and are called LHS or X-part of a functional dependency
and
att_y are attributes and are called RHS or Y-part of a functional dependency

i store the attributes accessed from the database in file "text1.txt"
X-part attributes in "text2.txt"
Y-part attributes in "text3.txt"

now to find the primary key what i need to do is...
i need all the X-part attributes without repeating any attribute and delete those attributes which are present on the Y-part.

so

Primary Key = X-part(no duplication) - Y-part

i'd be sooo very thankful if u could code this part for me in C asap. i dont think its too difficult for a pro programmer who is thorough with C programming.
please can u do it in an hour or so ? please give it a try.
thank u soo much for showing an interest. hav a gr8 day.

commented: You have got to be freaking kidding. Do your own homework. -2

## omol -2

Its not hard at all, but a pro gets paid.

commented: a pro also doesnt troll entry-level C programming boards for homework-seekers -2

lol !
am seriously ready to pay a reasonable amount for this... around $20 but pls pls help me out of it asap. i need to submit tomorrow. jes this part pending. ok how do u enter a filename..? i mean the format? FILE *fp; fp = fopen("C:\project\text1.txt","a+"); this is returning an error.. not able to open the file !! :( commented: that's just pathetic. don't insult us -2 ## Banfa 597 That is because \ is the escape character in string literals in C (and C++) so '\t' is a tab character and '\p' is p (I think). To get an actual slash you need '\\' ## Narue 5,707 am seriously ready to pay a reasonable amount for this... around$20

Daniweb is not a programmer rental service. Offering to pay someone to do your homework is the kiss of death around here.

i need to submit tomorrow.

Congratulations, you've just gotten a lesson in time management from the school of hard knocks.

fp = fopen("C:\project\text1.txt","a+");

Double up the backslashes or reverse them, so they're not treated like escape sequences:

fp = fopen("C:\\project\\text1.txt","a+");
fp = fopen("C:/project/text1.txt","a+");

so '\t' is a tab character and '\p' is p (I think)

'\p' is an unrecognized escape sequence, and thus, undefined behavior.

commented: :) +8

## myth_terry -6

oh right. didn't think bout it. thank u lots :)
will give it one more try.

$20? LOL. we don't want your spare change. we'll help you for free. but only if you're ready to do the work. you couldnt afford us, otherwise. ## myth_terry -6 hey buddy. no offence. i'm a student and that all i can afford. :( well i have done most of the coding. i have found out a solution to copy the strings from file to a string array. the problem now is how do i remove the duplicate strings from an array. I want to copy strings from array A[] to array B[] without duplicate entries. please somebody suggest a code for this. AND how to i detect whether the entries in an array are over without knowing the count as to how many entries exist?? ## jephthah 1,888 no offence. i'm a student and that all i can afford that's why we HELP for FREE. don't you have some sort of academic integrity policy at your school? I'm sure paying for homework is in violation of that. i just turned in someone to their engineering dean and course professor for this. ## Aia 1,977 that's why we HELP for FREE. don't you have some sort of academic integrity policy at your school? I'm sure paying for homework is in violation of that. i just turned in someone to their engineering dean and course professor for this. He called you buddy! Doesn't everybody know that you only have one buddy, and it has stripes, and camouflages itself as a stuff animal when normal people is around? Here's another one getting ripe for failure. No paying attention to Narue> Offering to pay someone to do your homework is the kiss of death around here. ## Banfa 597 the problem now is how do i remove the duplicate strings from an array. I want to copy strings from array A[] to array B[] without duplicate entries. please somebody suggest a code for this. AND how to i detect whether the entries in an array are over without knowing the count as to how many entries exist?? Before you add a string to A[] check all the entries that are already in it to see if any are the same as the one you are about to add and don't add it if any are. AND You can't storing the number of used entries in an array is an integral part of being able to use it. ## myth_terry -6 hey hey !! it ain't my homework... its jes a small part of the project am doing as my final year project of engineering.. it has got to do mostly with the databases and VB. this C code am usnig it as a .exe file in VB jes to arrange the attributes i get from a table from oracle 9i. i usually work on system programming and java. have forgotten some parts in C which i'd learnt in my first year. that was why i am requesting u guys out there for some help.. i cant proceed without this part. please don't get offended and ehlp me out of this first.. its a humble request :( ## Narue 5,707 it ain't my homework... its jes a small part of the project am doing as my final year project of engineering.. That fits our definition of homework. its a humble request You can't get everything you want just by being humble. You've posted a tiny amount of code and shown no real effort in solving the problem beyond begging and offering money for someone else to do it. This seems like a huge waste of time for those of us who are here with the goal of teaching. ## jephthah 1,888 ... i'd be sooo very thankful if u could code this part for me in C asap. ... please can u do it in an hour or so ? please give it a try. ... am seriously ready to pay a reasonable amount for this... around$20 ... i need to submit tomorrow.

dude... i'm not going to make threats, but this looks pretty incriminating to me. and it's worse than cheating on homework, you were offering to pay us to help you cheat on your final semester project.

your problem is trivial and you could have had all the help you needed and then some, if you would have just come in without the hysterics.

but rather than take responsibility and work it out like everyone else, you've gone and compromised your academic integrity. I'm not going to spend the time to track you down and turn you in ... but you'll know. and you'll remember this day.

my screen name is a legendary figure who did the same thing: Panicked right before leading a major battle, and promised God he would make a sacrifice of a member of his household if he could get help to defeat his enemies. Now, Jephthah could have won the battle without divine intervention, but by trying to game the system, he wound up having to make his only daughter a burnt offering. Judges 11:29-40, if you're interested.

.

## myth_terry -6

hey everybody out there... if u carefully go through each post in this thread.. it was one of u'll who'd posted asking for money.. and i started my reply with a "lol" which means "laugh out loud" for ur kind info. it simply means that i was kidding bout making financial payments on this site. if i had an intention of paying for my project i would never get into a free help forum.

And those who have been grateful to help me out of this hav given me enuf clues to sort out most of the problem. i was just not understanding how to trace the end of strings in an array.

i never meant to offend anybody or am not even making any academic blunders by doing this. and i repeat again, the money thing was jes a joke to that context. that too only bcos one of the users asked for it.. i thin the person who asks for money on a free forum is equally guilty to who offers it.

and instead of referring a book i'm asking u'll thats it. i dont need the entire code. i jes need the logic as to how it works..

but in a C forum i never expected people to giv me moral lessons rather than C lessons.. i guess people here r jes to find others mistakes or so called "mistakes".

thank u anyways... for ur "moral" lessons.. but sry i dont have time for it...

## jephthah 1,888

and if you think Ethics aren't a HUGE issue in today's business world, you surely have been living in a cave. hell, I have to study an entire section on Ethics in order to take my PE (professional engineer's) Exam.

but whatever, it's clear you were not kidding. so you're either exposing yourself as a liar, or you're just covering your tracks because you're scared. I'll give you the benefit of the doubt and assume the latter.

Now anyhow, where were we .... oh, yes. we've addressed the double backslash filename issue (\\), so what other questions do you have :)

.

NA

## myth_terry -6

friends... i have solved the problem. thank you to all of those who provided me with very important clues. i hav completed the project.

below i will include the code which i have written. i havent given much importance to the code efficiency because of my urgency. and the variable i have used are according to my convenience and purpose. so if anybody dont understand dont hesitate to drop in a query.

another request would be please anybody who know the solution to problems programmers are facing here, first concentrate on solving the problem rather than deviating from the topic.

have a gr8 day ! :)

#include<stdio.h>
#include<conio.h>
#include<string.h>
#define MAX 100

struct prim
{
char name[MAX];
struct prim *next;
};
typedef struct prim *PRIM;

PRIM getmem()
{
PRIM x;
x=(PRIM)malloc(sizeof(struct prim));
if(x==NULL)
exit(0);
return x;
}

PRIM insert(char *item,PRIM first)
{
PRIM temp;
PRIM cur;

temp=getmem();

strcpy(temp->name,item);
temp->next=NULL;

if(first==NULL)
return temp;

cur=first;

while(cur->next!=NULL)
cur=cur->next;

cur->next = temp;

return first;
}

PRIM rem_att(char *item,PRIM first)
{
PRIM prev,cur;
if(first==NULL)
return NULL;

if(strcmp(item,first->name)==0)
{
cur=first;
first=first->next;
free(cur);
return(first);
}

prev=NULL;
cur=first;
while(cur!=NULL && strcmp(item,cur->name)!=0)
{
prev=cur;
cur=cur->next;
}

if(cur==NULL)
return first;

prev->next=cur->next;
free(cur);
return first;
}

void main()
{
FILE *fp;
PRIM primary=NULL,primary1=NULL;
int i,j,k,count,xcount,ycount,atcount,pcount,flag;
char attrib[MAX][MAX],X[MAX][MAX],Y[MAX][MAX],PK[MAX][MAX],prim[MAX][MAX];
char line[MAX];

clrscr();

for(i=0;i<MAX;i++)
{
for(j=0;j<MAX;j++)
{
attrib[i][j]='\0';
X[i][j]='\0';
Y[i][j]='\0';
PK[i][j]='\0';
prim[i][j]='\0';
}
line[i]='\0';
}

fp=fopen("attrib.txt","r");
if(fp != NULL)
{
atcount=0;
i=0;
while(fgets(line,sizeof line,fp) != NULL)
{
strcpy(attrib[i],line);
i++;
atcount++;
}
fclose(fp);
}

else
printf("\n could not open attrib");

fp=fopen("X.txt","r");
if(fp!=NULL)
{
xcount=0;
i=0;
while(fgets(line,sizeof line,fp)!=NULL)
{
strcpy(X[i],line);
i++;
xcount++;
}

fclose(fp);

printf("\n X array: \n\n");
for(i=0;i<xcount;i++)
printf("\t %s", X[i]);
}

else
printf("\n could not open X");

fp=fopen("Y.txt","r");
if(fp!=NULL)
{
ycount=0;
i=0;
while(fgets(line,sizeof line,fp)!=NULL)
{
strcpy(Y[i],line);
i++;
ycount++;
}
fclose(fp);

printf("\n------------\n\n\n Y array: \n");
for(i=0;i<ycount;i++)
printf("\t %s", Y[i]);
}

else
printf("\n could not open Y");

for(i=0;i<xcount;i++)
{
primary=insert(X[i],primary);
}

for(i=0;i<ycount;i++)
{
primary=rem_att(Y[i],primary);
}

primary1=primary;
printf("\n\n Pre-Primary Key: \n");
while(primary1!=NULL)
{
printf("\t %s",primary1->name);
primary1=primary1->next;
}

primary1=primary;
i=0;
pcount=0;
while(primary1!=NULL)
{
strcpy(PK[i],primary1->name);
i++;
primary1=primary1->next;
pcount++;
}

count=0;
for(i=0;i<pcount;i++)
{
flag=0;
j=0;
while(j<MAX)
{
if(strcmp(prim[j],PK[i])==0)
flag=1;
j++;
}

if(flag==0)
{
k=0;
while(prim[k][0]!='\0')
k++;
strcpy(prim[k],PK[i]);
count++;
}
}

/*
primary1=primary;
fp=fopen("PK.txt","w");
printf("\n\n PRIMARY KEY");
while(primary1!=NULL)
{
fputs(primary1->name,fp);
printf("\n %s",primary1->name);
primary1=primary1->next;
}
fclose(fp);
*/
printf("\n\n\n xcount = %d \n\n ycount = %d",xcount,ycount);

printf("\n\n\n Final Primary Key: \n\n");
fp=fopen("PK.txt","w");
if(fp!=NULL)
{
for(i=0;i<count;i++)
{
printf("\t %s",prim[i]);
fputs(prim[i],fp);
}
fclose(fp);
}
else
{
printf("\n\n cannot open PK");
}
getch();
}
commented: rubbish -2