| |

VerySource

 Forgot password?
 Register
Search
View: 1431|Reply: 12

Solve two problems, master help

[Copy link]

1

Threads

7

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-1-4 22:20:01
| Show all posts |Read mode
1. Set up a vector map file (vec.dat), the record format is as follows
1, Road, 3
321230.0, 3545678.0
321260.0, 3545658.0
321330.0, 3545778.0
2, Street, 5
321240.0, 3545678.0
321560.0, 3545858.0
321630.0, 3545578.0
321830.0, 3545378.0
321290.0, 3545258.0
4, Land, 6
...
None of them are the record number, arc name, graphic coordinate points, and the coordinate pairs of the record. Design a vector data structure that meets the storage record format, write 3 programs, read the data into memory and store it according to the designed data structure, and then translate the map by 1000m in the x direction and 500 in the y direction. Then write the translated graphic into the original file in the original file format.

2. There is an image "Image.dat" (single byte, no head and tail) of N rows and M columns. Write a C program to read the image into the memory group IMAGE [i] [j]. Densify the image and write it to the file "Result.dat"

Heroes help, it is best to give examples. I use VC ++ 6, I can't adjust it, especially formatting read and write files! Help
Reply

Use magic Report

1

Threads

7

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-1-5 09:12:01
| Show all posts
I like it ~~~
Reply

Use magic Report

0

Threads

36

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

Post time: 2020-1-5 10:12:01
| Show all posts
Seems to be reduced to a matrix operation at the end.
Specifically forgotten.
Reply

Use magic Report

1

Threads

7

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-1-5 11:39:01
| Show all posts
My biggest problem now is that I can't read and write data correctly from the file.
Reply

Use magic Report

1

Threads

7

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-1-5 16:48:01
| Show all posts
Zaiding ~~~~~~~~~
Reply

Use magic Report

1

Threads

7

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-1-6 14:12:01
| Show all posts
#include <stdio.h>
#include <stdlib.h>

struct arc_data
{
float x, y;
struct arc_data * next;
};
struct arc_type
{
int id, point;
char name [10];
struct arc_data * data;
struct arc_type * next;
};



void main ()
{
FILE * fin, * fout;
struct arc_type * list, * l1, * l2;
struct arc_data * head, * p1, * p2;

fin = fopen ("E:\\data.dat", "rb");
if (fin == NULL)
{
printf ("err");
exit (1);
}
Ransom
int n1 = 0;

while (! feof (fin))
{
l1 = (struct arc_type *) malloc (sizeof (struct arc_type));
fscanf (fin, "% d,% s% d",&l1-> id,&l1-> name,&l1-> point);

for (int i = 0, n2 = 0; i <l1-> point; i ++)
{
p1 = (struct arc_data *) malloc (sizeof (struct arc_data));
fscanf (fin, "% f,% f",&p1-> x,&p1-> y);

n2 ++;
if (n2 == 1)
head = p1;
else
p2-> next = p1;

p2 = p1;
}
 p2-> next = NULL;
l1-> data = head;

n1 ++;
if (n1 == 1)
list = l1;
else
l2-> next = l1;
l2 = l1;
}
l2-> next = NULL;
    fclose (fin);
Ransom
Ransom
fout = fopen ("E:\\data.dat", "w +");
if (fout == NULL)
{
printf ("err!");
exit (1);
}

l1 = list;
while (l1! = NULL)
{
fprintf (fout, "% d,% s% d\n", l1-> id, l1-> name, l1-> point);
while (l1-> data! = NULL)
{
l1-> data-> x = l1-> data-> x + 1000;
l1-> data-> y = l1-> data-> y + 500;

fprintf (fout, "% 6.1f,% 6.1f\n", l1-> data-> x, l1-> data-> y);
l1-> data = l1-> data-> next;
}
l1 = l1-> next;
}
fclose (fout);

}

I achieved the first question. But why can this program be executed only once? Please ask master
Reply

Use magic Report

0

Threads

6

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-6 15:12:01
| Show all posts
while (! feof (fin))
{
l1 = (struct arc_type *) malloc (sizeof (struct arc_type));
fscanf (fin, "% d,% s% d",&l1-> id,&l1-> name,&l1-> point);

    for (int i = 0, n2 = 0; i <l1-> point; i ++)
{
p1 = (struct arc_data *) malloc (sizeof (struct arc_data));
fscanf (fin, "% f,% f",&p1-> x,&p1-> y);

n2 ++;
if (n2 == 1)
head = p1;
else
p2-> next = p1;

p2 = p1;
}
 p2-> next = NULL;
l1-> data = head;

n1 ++;
if (n1 == 1)
list = l1;
else
l2-> next = l1;
l2 = l1;
}
Reply

Use magic Report

0

Threads

6

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-6 15:18:02
| Show all posts
Why wasn't l1 released?
Reply

Use magic Report

1

Threads

4

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-6 15:30:01
| Show all posts
I won't, but help you! !! !!
Reply

Use magic Report

1

Threads

7

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-1-11 16:27:01
| Show all posts
china1839: How do I modify it? (Ms didn't see the change) thank you
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list