Unable to open a file.

Posted on 2004-11-08
Last Modified: 2010-04-15
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;


Question by:ksanand_be
    LVL 16

    Accepted Solution

    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.


    Author Comment

    Brilliant! Thanks a lot! The code works to the perfection.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    This tutorial is posted by Aaron Wojnowski, administrator at  To view more iPhone tutorials, visit This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
    Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
    The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
    The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now