c write to file append code example
Example 1: php write to file
$myFile = "testFile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "Bobby Bopper\n";
fwrite($fh, $stringData);
$stringData = "Tracy Tanner\n";
fwrite($fh, $stringData);
fclose($fh);
Example 2: obj c write file
-(void)write:(NSString *)dir file:(NSString *)ff{
NSArray *paths = NSSearchPathForDirectoriesInDomains
(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fileName = [NSString stringWithFormat:[@"%@/" stringByAppendingString:dir],
documentsDirectory];
NSString *content = ff;
[content writeToFile:fileName
atomically:NO
encoding:NSStringEncodingConversionAllowLossy
error:nil];
}
Example 3: write a binary file c
FILE *write_ptr;
write_ptr = fopen("test.bin","wb");
fwrite(buffer,sizeof(buffer),1,write_ptr);