popen and fgets

This is a discussion on popen and fgets within the C Programming forums, part of the General Programming Boards category; Hello, I need to make a program to read a text file and set it to a label... I thought ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    2

    popen and fgets

    Hello, I need to make a program to read a text file and set it to a label...

    I thought I could use fgets and popen to do it but I'm lost on programming it!!

    Check out the code:

    FILE *page= (FILE *)popen("cat rox.txt","r");
    GtkWidget * label = lookup_widget(GTK_WIDGET(button), "label1");
    gtk_label_set_text(GTK_LABEL(label),page);

    I know that gtk_label_set_text is waiting a gchar, and I'm not sending a gchar, that's why I thought fgets would help but I couldn't do it too...

    I'm lost, if anyone could please write these 3 lines of code working to set the label with a textfile would help a lot.

    I've read much on google I'm almost giving it up...

    Thanks for reading.

  2. #2
    Registered User
    Join Date
    Dec 2005
    Location
    Colchester, Essex, United Kingdom.
    Posts
    31
    Read text from the file using fread().

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,422
    > FILE *page= (FILE *)popen("cat rox.txt","r");
    1. What's the point of casting?
    2. What's the point of popen?

    I mean, all you've achieved here is
    FILE *page = fopen( "rox.txt", "r" );

    > I know that gtk_label_set_text is waiting a gchar, and I'm not sending a gchar
    So read a line
    char buff[BUFSIZ];
    fgets ( buff, BUFSIZ, page );
    gtk_label_set_text(GTK_LABEL(label),buff);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. popen and fgets, underflow!
    By henrikstolpe in forum Linux Programming
    Replies: 0
    Last Post: 02-06-2009, 02:39 AM
  2. popen with a fossil (split from bumped thread)
    By leandroaz in forum Windows Programming
    Replies: 3
    Last Post: 09-12-2008, 01:47 PM
  3. popen help
    By ojschubert in forum C Programming
    Replies: 2
    Last Post: 02-27-2005, 11:32 PM
  4. popen and fgets problem
    By dkt in forum C Programming
    Replies: 1
    Last Post: 10-08-2001, 11:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21