Thread: popen and fgets

  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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > 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, 03: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-28-2005, 12:32 AM
  4. popen and fgets problem
    By dkt in forum C Programming
    Replies: 1
    Last Post: 10-08-2001, 11:33 AM