• C

Unable to open a file.

extern"C" {

struct account
 char *name;
 float cur_exp,prev_debit, prev_credit;
 struct account *next;
typedef struct account acc;
display(acc * );
acc add(acc **);
int main()
int i;
acc *list_acc;
list_acc = NULL;
//Print the various options available to the user
printf("1. View the records\n");
printf("2. Calcuate current per head expenditure\n");
printf("3. View total expenditure till date\n");
printf("4. Who spends the most\n");
printf("5. Graphical representation\n");
printf("6. Add/Delete a member\n");
scanf("%d", &i);
   case 1: printf ("Viewing records");

   case 2:
   case 3:
   case 4:
   case 5:
   case 6:
   printf("Input data unknown\n");
display(acc *list_ptr)
    while(list_ptr != NULL)

      printf("\n %s" ,list_ptr->name);
      list_ptr  = list_ptr->next;
acc add(acc **list_ptr)
   FILE *fp;
   acc *temp, *new_blk;
   temp = *list_ptr;
   int i,number;
   printf(" Enter the number of people in your house");
   scanf("%d", &number);
   fp = fopen("c:\tcplus\tc\data.txt","w");
   printf("Error opening file\n");   //Unable to open file is a positive case in my program.
        new_blk = (acc *)malloc(sizeof(acc));
        printf("\nEnter the name of person %d", i);
        new_blk->next = NULL;
        if(*list_ptr == NULL)
         temp = new_blk;
         *list_ptr = temp;
         temp->next = new_blk;
         temp = temp->next;


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

A backslash is an escape character in C. It is used to denote control characters such as newline (\n) and carriage return (\r). Thus, in order to put a backslash in a string (i.e. in order to avoid the compiler treating it and the character following it as a control code) you have to put down two backslashes. That is, to get a backslash in a string you must write "\\".

So, you're filename should be written as:

fp = fopen("c:\\tcplus\\tc\\data.txt","w");

Otherwise the compiler will treat the \t's as tabs.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ksanand_beAuthor Commented:
Brilliant! Thanks a lot! The code works to the perfection.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.