• 0

Reading a dropbox text file help!


Question

Hi

I am currently making a program for a local radio station.

Their schedule updates regularly, but as it is quite hard to push out an update for the whole program each time this happens, i am hoping to store the schedule in a text file on dropbox, and to have it display in a label, in the program.

 

I cant figure out how to make the label say the contents of the text file, and I was wondering if someone would help me to get over my issue.

 

Thanks in Advance

Link to comment
https://www.neowin.net/forum/topic/1263452-reading-a-dropbox-text-file-help/
Share on other sites

2 answers to this question

Recommended Posts

  • 0
  On 08/07/2015 at 19:59, Harry Smith said:

Hi

I am currently making a program for a local radio station.

Their schedule updates regularly, but as it is quite hard to push out an update for the whole program each time this happens, i am hoping to store the schedule in a text file on dropbox, and to have it display in a label, in the program.

I cant figure out how to make the label say the contents of the text file, and I was wondering if someone would help me to get over my issue.

Thanks in Advance

The actual code will differ depending on the language, but here's a general outline:

a) Open & read target file into program buffer. The type of program buffer will largely depend on the data format of the file you're reading and what language you're using. For simplicity's sake, let's say you're reading plain text:

#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>

int
main ( int argc, char **argv ) {

	int		fd;
	struct stat 	file;
	char		*text;
	size_t		result;

	if ( argc < 2 ) {
		fprintf ( stderr, "Please provide a schedule file argument!\n" );
		return EXIT_FAILURE;
	}

	if ( -1 == ( fd = open ( argv[1], O_RDONLY ) ) ) {
		fprintf ( stderr, "Failed to open schedule: %s\n", strerror ( errno ) );
		return EXIT_FAILURE;
	}

	fstat ( fd, &file );  
	text = malloc ( file.st_size + 1 );

	result = read ( fd, text, file.st_size );
	
	/* zero terminate it */
	text[file.st_size] = '\0';
	
	printf ( "Successfully read schedule (%u bytes) into program buffer.\n", result );

	/* do something with the text.. */

	/* clean up */
	close ( fd );
	free ( text );

	return EXIT_SUCCESS;
}	
$ gcc -o schedule schedule.c && ./schedule file.txt
Successfully read schedule (858 bytes) into program buffer.
b) Display plain text in a GUI. Again this is highly dependent on the toolkit used. Most of them have widgets that can display text. For instance, in GTK:

gtk_label_new ( text );
Or:

GtkLabel *schedule = gtk_label_new ( NULL );
gtk_label_set_text ( schedule, text );
Your toolkit should provide something similar.
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • TotalCommander can use Everything as its search engine, Files should be able too.
    • App size is 441.1 MB, larger and larger with each release. Using doomed and bloated WinUI for foundation was a mistake.
    • Sound Booster 1.12 Build 544 by Razvan Serea Increase volume on your laptop. Boost the volume of even very quiet speakers. Raise volume above maximum. Letasoft Sound Booster can be used as an extra amplifier when the volume of the program you are listening to is too low for comfortable listening and you feel that your PC’s speakers can produce a louder sound. This can be the case when the audio or video has been recorded at the level below normal. Or, for example, when the other person’s microphone you are talking to on Skype, is not working properly. There can be a plenty of other reasons why the sound is being too quiet and there is not much you can do about it except buy external speakers. Sound of any application that is being played in the system can be amplified up to 500%. Letasoft Sound Booster can raise volume of programs like web browsers, on-line communication software (Teams, Discord, Zoom), any kind of media player or games. Simply put, volume of virtually any program that can play any sound in PC, can be boosted to a comfortable level with Letasoft Sound Booster. You can control current volume with the pop-up slider from the system tray. Alternatively, you can assign system-wide hot keys for increasing and decreasing, and use them when you need to adjust volume Letasoft Sound Booster constantly monitors current gain level and prevents samples from clipping, thus reducing all major sound distortions. Download: Letasoft Sound Booster 1.12.0.544 | 7.3 MB (14-Day Free Trial) View: Letasoft Website | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • how about a very lite version that only have column view. one view that windows explorer does not have.
  • Recent Achievements

    • Reacting Well
      Ainajohn earned a badge
      Reacting Well
    • One Month Later
      Ainajohn earned a badge
      One Month Later
    • Week One Done
      Ainajohn earned a badge
      Week One Done
    • Week One Done
      pirateshiptours earned a badge
      Week One Done
    • Week One Done
      Zojaji earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      743
    2. 2
      ATLien_0
      185
    3. 3
      +FloatingFatMan
      151
    4. 4
      Xenon
      116
    5. 5
      wakjak
      113
  • Tell a friend

    Love Neowin? Tell a friend!