C 如果在循环中,指针是否自行移动到数组中的下一行?

C 如果在循环中,指针是否自行移动到数组中的下一行?,c,C,在我的程序中,指针是文件中文本第一行的地址,指针是文件中文本第三行的地址。我正在尝试打印不同文件中地址之间的文本。我想知道当指针遇到新行或空字符时,它会自动移动到下一行吗?如果没有,请解释以下代码会导致什么类型的错误 int m=row_ew[pick_ew]; /* m is equal to 2, which is the address to the first element of the third row in the array*/ int n=pos_ew[pick_ew]

在我的程序中,指针是文件中文本第一行的地址,指针是文件中文本第三行的地址。我正在尝试打印不同文件中地址之间的文本。我想知道当指针遇到新行或空字符时,它会自动移动到下一行吗?如果没有,请解释以下代码会导致什么类型的错误

 int m=row_ew[pick_ew]; /* m is equal to 2, which is the address to the first element of the third row in the array*/ 
 int n=pos_ew[pick_ew]; /* n is equal to the index of the word in the third line to increment the pointer position to the address of the first character of the word*/

 pointer_ew=file[m]+n+strlen(endword); /* Add the length of the word to increment the pointer to the end of the word*/

 pointer=file[i]; /*i is 0, address to the first element of the first row in the array*/

 while(pointer!=pointer_ew)
 {
   fputc(*pointer,outfile);
   pointer++;
 }

它工作得很好,但是我在我试图复制的文件中没有看到随机字符。但我确实在复制到的文件中看到了它。在行首,我在输出文件中看到一些额外的随机字符(在文本文件中,“换行符”是一个常规字符,在类Unix系统中为10(
\n
),在旧Mac上为12(
\r
),在Dos或Windows上为10 12(
\r\n

这应该一个字符一个字符地复制文件,不管你有什么,直到你点击结束指针为止(注意,我不确定你在做什么,但是如果
pointer\u ew
没有指向原始字符串[1]的一部分,你的程序将尝试输出RAM中的任何内容,直到操作系统用segfault终止你的程序)


[1] 。如中所示,如果您没有根据
指针
(类似于
指针\u ew=pointer+5
)。如果指针指向另一个字符串,则会出现分段错误。

不,指针对文件i/o一无所知。您正在写入该地址的内容。由于您没有显示,因此必须确定您要执行的操作。我添加了一些代码,我所要做的只是将文件的一部分复制并粘贴到另一个文件中。地址在文件中的两行上。@我猜应该是这样的work@CharlesShiller:它可以工作,但我在行首看到一些随机字符。检查您是如何获得文件的[I]我猜它应该可以工作(如果您没有内存问题).但主要的一点仍然是正确的。如果你一个字符一个字符地写,换行符并不重要——它们只是另一个字符。它工作正常,但我在试图复制的文件中没有看到随机字符。但我确实在复制到的文件中看到了它。