• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Objective-C BufferedReader
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Objective-C BufferedReader


  • Subject: Objective-C BufferedReader
  • From: Hamish Allan <email@hidden>
  • Date: Sat, 12 Feb 2005 22:39:44 +0000

Hi,

I have as yet been unable to find anything written in Objective-C that provides the functionality of Java's java.io.BufferedReader.

1) Does such a library object exist, and if so, where?

Assuming not, I thought I might try to implement it naively as below (readLine hard-coded to stdin for pedagogical purposes). It works fine for strings that are less than BUFFER_LENGTH characters long, but if they are over, fgets() never returns. I know this is not really a Cocoa question, but since I was asking (1) above, I thought I'd also ask here:

2) What's wrong with the following code?

- (NSString *)readLineFromStdin
{
NSMutableString *ret = [NSMutableString stringWithCapacity:BUFFER_LENGTH];


	char buf[BUFFER_LENGTH + 1];
	char *chars = fgets(buf, BUFFER_LENGTH, stdin);

if (chars != NULL)
{
char *endl = strchr(chars, '\n');
while (endl == NULL)
{
[ret appendString: [NSString stringWithCString:buf length:BUFFER_LENGTH]];
endl = strchr(chars, '\n');
}
[ret appendString: [NSString stringWithCString:buf length:(endl - buf)]];
}

return ret;
}


Many thanks,
Hamish

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Objective-C BufferedReader
      • From: Jason Jobe <email@hidden>
  • Prev by Date: check status of secure webpage?
  • Next by Date: Re: check status of secure webpage?
  • Previous by thread: Re: check status of secure webpage?
  • Next by thread: Re: Objective-C BufferedReader
  • Index(es):
    • Date
    • Thread