{"id":859,"date":"2022-08-30T15:08:22","date_gmt":"2022-08-30T15:08:22","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/construct-c-code-am-i-missing-something-closed-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:08:22","modified_gmt":"2022-08-30T15:08:22","slug":"construct-c-code-am-i-missing-something-closed-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/construct-c-code-am-i-missing-something-closed-collection-of-common-programming-errors\/","title":{"rendered":"Construct C code &#8211; am i missing something? [closed]-Collection of common programming errors"},"content":{"rendered":"<p>My compiler pushes out the following output:<\/p>\n<pre><code>blah.c:10:27: warning: declaration of 'struct studnet' will not be visible outside of this function [-Wvisibility]\nint getStudentData(struct studnet *current_ptr); \/\/ struct function format \n                          ^\nblah.c:14:20: error: passing 'struct student' to parameter of incompatible type 'struct studnet *'\n    getStudentData(str);\n                   ^~~\nblah.c:10:36: note: passing argument to parameter 'current_ptr' here\nint getStudentData(struct studnet *current_ptr); \/\/ struct function format \n                                   ^\nblah.c:20:27: warning: declaration of 'struct studnet' will not be visible outside of this function [-Wvisibility]\nint getStudentData(struct studnet *current_ptr){\n                          ^\nblah.c:20:5: error: conflicting types for 'getStudentData'\nint getStudentData(struct studnet *current_ptr){\n    ^\nblah.c:10:5: note: previous declaration is here\nint getStudentData(struct studnet *current_ptr); \/\/ struct function format \n    ^\nblah.c:30:9: warning: implicit declaration of function 'fscan' is invalid in C99 [-Wimplicit-function-declaration]\n        fscan(studentFile, \"%20s %20s has a GPA of %f\\n\"\n        ^\nblah.c:31:30: error: incomplete definition of type 'struct studnet'\n                , current_ptr-&gt;fname, current_ptr-&gt;lname, current_ptr-&gt;gpa);\n                  ~~~~~~~~~~~^\nblah.c:20:27: note: forward declaration of 'struct studnet'\nint getStudentData(struct studnet *current_ptr){\n<\/code><\/pre>\n<h2>Let&#8217;s break down these warnings and errors:<\/h2>\n<p>A number of the warnings are because you mis-spelled <code>student<\/code> as <code>studnet<\/code>. For example, this one:<\/p>\n<pre><code>blah.c:31:30: error: incomplete definition of type 'struct studnet'\n                , current_ptr-&gt;fname, current_ptr-&gt;lname, current_ptr-&gt;gpa);\n                  ~~~~~~~~~~~^\n<\/code><\/pre>\n<p>We also should pass a pointer instead of a stuct by value. Changing a line to <code>getStudentData(&amp;str);<\/code> would help this following error:<\/p>\n<pre><code>blah.c:14:20: error: passing 'struct student' to parameter of incompatible type 'struct studnet *'\n    getStudentData(str);\n                   ^~~\n<\/code><\/pre>\n<p>And finally, I imagine that you wanted <code>fscanf<\/code> and not <code>fscan<\/code>, which would fix this error:<\/p>\n<pre><code>blah.c:30:9: warning: implicit declaration of function 'fscan' is invalid in C99 [-Wimplicit-function-declaration]\n        fscan(studentFile, \"%20s %20s has a GPA of %f\\n\"\n        ^\n<\/code><\/pre>\n<p>There&#8217;s no warning for this following error (yet, because of the fscanf error), but if I fix the above errors, I get one more warning that needs to be fixed. This can be done by passing <code>&amp;current_ptr-&gt;gpa<\/code> instead of <code>current_ptr-&gt;gpa<\/code>.<\/p>\n<pre><code>blah.c:31:59: warning: format specifies type 'float *' but the argument has type 'double' [-Wformat]\n                , current_ptr-&gt;fname, current_ptr-&gt;lname, current_ptr-&gt;gpa);\n                                                          ^~~~~~~~~~~~~~~~\n<\/code><\/pre>\n<p id=\"rop\"><small>Originally posted 2013-11-09 22:49:18. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>My compiler pushes out the following output: blah.c:10:27: warning: declaration of &#8216;struct studnet&#8217; will not be visible outside of this function [-Wvisibility] int getStudentData(struct studnet *current_ptr); \/\/ struct function format ^ blah.c:14:20: error: passing &#8216;struct student&#8217; to parameter of incompatible type &#8216;struct studnet *&#8217; getStudentData(str); ^~~ blah.c:10:36: note: passing argument to parameter &#8216;current_ptr&#8217; here int [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-859","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/859","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=859"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/859\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=859"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=859"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=859"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}