我无法弄清楚这一点.当我在我的Windows机器上使用Code :: Blocks编译这段代码时,它运行得很好,但是当我尝试使用Cygwin下的Make或者在学校的实际Unix机器上编译它时,我得到了下面的奇怪行为.我将"client1.txt"传递给translate().
void translate(char* filepath){
char output_filepath[181];
strcpy(output_filepath, filepath);
printf("%s\n", output_filepath); //this prints out "client1.txt" which is correct
char* ptr = strcat(output_filepath, ".translated");
printf("%s\n", output_filepath); //this prints out ".translated" which is wrong
printf("%s\n", ptr); //also prints out ".translated" wrong again
...more stuff...
}
Run Code Online (Sandbox Code Playgroud)
当尝试在output_filepath上使用fgets时,这会导致分段错误.有谁知道发生了什么?我需要解释更多吗?它必须能够在Unix下编译.
这是整个程序,我希望它不会太长.这是我老师给我们工作的一个程序,但我甚至无法让它运行.它只是给我一个分段错误,我已经跟踪了上面的部分.
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
struct tparam{
int tid;
};
int NTHREADS = 5;
#define LOOPS 10000
int qfilled = 0;
int qin = 0;
int qout = 0; …Run Code Online (Sandbox Code Playgroud)