-- Define theString and the target file
set theString to {"This", "That"}
set theFile to (path to desktop as text) & "Pantones.csv"
-- Execute the write handler
set theResult to writeTo (theFile, theString)
on writeTo(targetFile, theData)
set openFile to open for access file targetFile with write permission
set theCount to the count of items in theData
set n to 0
--write to the target file & add a comma after every item except the last
repeat theCount times
set n to n + 1
if n is not theCount then write item n of theData & "," to openFile as string
if n is theCount then write item n of theData to openFile as string
end repeat
close access openFile
end writeTo
我已成功编译并执行。但未找到匹配是在打印匹配找到之前打印五次。请帮忙
答案 0 :(得分:3)
这是错误的:
(void) memcpy (y, 0x00, sizeof(y));
这意味着您希望从地址sizeof(y)
读取y
字节为0
,这当然会发生段错误。
你想要这个:
char y[20] = {0};
或
memset(y, 0x00, sizeof(y));
答案 1 :(得分:2)
问题出在这里
(void) memcpy (y, 0x00, sizeof(y));
您将memcpy()的源指针指定为零。您使用错误的函数在缓冲区y中设置零。您应该使用memset()
代替memcpy()
错误:(void) memcpy (y, 0x00, sizeof(y));
正确:memset(y, 0x00, sizeof(y));