Beginner problems

I do this so far:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <stdio.h>
#include <string.h>

struct n_rowdata
{
    char m_name[27];
    char m_enable[1];
    char m_pointer[6];
    char m_crlf[2];
};

const char *myFile = "names.dat";
int startRecord = 101;
int endRecord = startRecord + 205;

int main()
{
    int i;
    FILE *f;
    struct n_rowdata r;

    f=fopen(myFile,"r+");
    if (!f)
        return 1;
    for (i=startRecord;i<=endRecord;i++)
    {
        int sz = sizeof(struct n_rowdata);
        fseek(f,sz*i,SEEK_SET);
        fread(&r,sz,1,f);
        printf("%s\%i",r.m_name,strlen(r.m_name));
    }
    fclose(f);
    return 0;
}


With this code I read a part of text file in structure and print it to window. Adressing and getting data goes well but in line printf where should be printed member
r.m_name
it prints whole row and strlen prints length of whole row instead of one member of strucure.

What is incorrect here and how to get contents of member
r.m_name
or other member printed?

And second, for what reason is this line
struct n_rowdata r;
. Since structure
n_rowdata
is declared at top of program it should be public. Or not?
Topic archived. No new replies allowed.