c언어 초보 질문합니다!

익명 사용자의 이미지

아래 코드에서 pop이 l-value여야한다는데 이것이 무엇인지 잘 모르곘습니다.

#define _CRT_SECURE_NO_WARNINGS
#include
#include
#include

typedef struct _popularity_t {
int rank;
int cnt;
char name[32];
} popularity_t;

int main(void) {
FILE* fp;
char* fname = "popular_names.txt";
popularity_t pop[20];
int i = 0;
int op; int search_rank; char search_name[32];
int N;
void* memset(void* pop, int N, size_t count);
printf("Input N");
scanf("%d", &N);

pop = (popularity_t *)malloc(sizeof(popularity_t));

fp = fopen(fname, "r");
if (fp == NULL) {
printf("Error in %s\n", fname);
return -1;
}
while (i < N && (fscanf(fp, "%d %s %d", &pop[i].rank, pop[i].name, &pop[i].cnt)) != EOF)
i++;

if (i < N) {
N = i;
pop = (popularity_t*)realloc(pop, sizeof(popularity_t) * N);
}

fclose(fp);

printf("Searching(1:rank, 2:name): ");
scanf("%d", &op);
switch (op) {
case 1:
printf("Input rank: "); scanf("%d", &search_rank);
for (i = 0; i < 20; i++){
if (search_rank == pop[i].rank) {
printf("%d %s %d \n", pop[i].rank, pop[i].name, pop[i].cnt);
}
}
break;
case 2:
printf("Input name: ");
scanf("%s", search_name);
for (i = 0; i < N; i++) {
if (strcmp(search_name, pop[i].name) == 0) {
printf("%d %s %d \n", pop[i].rank, pop[i].name, pop[i].cnt);
}
}
break;
}

free(pop);

return 0;
}

mypark의 이미지

배열로 선언하신 pop을 포인터로 바꾸시면 됩니다.
'void* memset(void* pop, int N, size_t count);' 메인문에 있는 이거 지우셔야합니다.

mypark의 이미지

스택 영역에 할당한 배열의 경우, 배열의 이름과 공간을 분리하는게 불가능합니다. 따라서 pop(배열의 이름)은 l-value(왼쪽에 올 수 있는 변수)가 될 수 없어요.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.