C
Chad
The input file is:
Params
1
2
3
4
5
6,7
Data
1,1
2,2
3,2
4,4
5,6
The output should be
1
2
3
4
5
6,7
1,1
2,2
3,2
4,4
5,6
Okay, with that, here is what I attempted, and what my computer
produced.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXLINE 10
int main(void)
{
char buff[MAXLINE];
char temp1[] = "Params\n";
char temp2[] = "Data\n";
FILE *inFile;
inFile = fopen("LAND2.txt", "r");
if (inFile != NULL)
{
while (fgets(buff, sizeof(buff), inFile) != NULL) {
if(strncmp(buff,temp1,sizeof(buff)) != 0)
fputs(buff, stdout);
if(strncmp(buff,temp2,sizeof(buff)) != 0)
fputs(buff, stdout);
}
}
if(feof) {
return 0;
}
fclose (inFile);
return 0;
}
Output
$gcc -Wall lunar.c -o lunar
$./lunar
Params
1
1
2
2
3
3
4
4
5
5
6,7
6,7
Data
1,1
1,1
2,2
2,2
3,2
3,2
4,4
4,4
5,6
5,6
$
Can someone enlighten me on where I'm screwing this up.
Chad
Params
1
2
3
4
5
6,7
Data
1,1
2,2
3,2
4,4
5,6
The output should be
1
2
3
4
5
6,7
1,1
2,2
3,2
4,4
5,6
Okay, with that, here is what I attempted, and what my computer
produced.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXLINE 10
int main(void)
{
char buff[MAXLINE];
char temp1[] = "Params\n";
char temp2[] = "Data\n";
FILE *inFile;
inFile = fopen("LAND2.txt", "r");
if (inFile != NULL)
{
while (fgets(buff, sizeof(buff), inFile) != NULL) {
if(strncmp(buff,temp1,sizeof(buff)) != 0)
fputs(buff, stdout);
if(strncmp(buff,temp2,sizeof(buff)) != 0)
fputs(buff, stdout);
}
}
if(feof) {
return 0;
}
fclose (inFile);
return 0;
}
Output
$gcc -Wall lunar.c -o lunar
$./lunar
Params
1
1
2
2
3
3
4
4
5
5
6,7
6,7
Data
1,1
1,1
2,2
2,2
3,2
3,2
4,4
4,4
5,6
5,6
$
Can someone enlighten me on where I'm screwing this up.
Chad