Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7797377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:39:47+00:00 2026-06-01T23:39:47+00:00

So here’s my code… My understanding is that I’m supposed to create a function

  • 0

So here’s my code… My understanding is that I’m supposed to create a function “map” that takes a function as an argument. It’s not going as planned. Any help would be completely amazing.

Here’s a compilable (well not compilable, but scaled down) version of the code:

#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
int main(int argc, const char *argv[])
{
//it should be apparent that I am quite new to C, I have some java experience.
struct linkedList {
   int count;
   int num;
   struct linkedList *next;
};
struct linkedList *head, *tail, *curr;
int count1=0;
int i=0;

int square(int v) {return v=v*v;}

void map(int (*func)(int v), struct linkedList){
    struct linkedList2 *head, *tail, *curr;
    for(curr=head; curr!=NULL; curr=curr->next){
        curr->num=func(curr->num);
        printList();
    }
}

void start(){
    printf("This program will ONLY accept integer input.\n");
    head=NULL;
    for(i=1;i<=4;i++) {
        count1++;
        curr=malloc(sizeof(struct linkedList));
        curr->count=count1;
        printf("Enter a number: ");
        scanf("%d", &curr->num);
        if(head==NULL) { head=curr; }
        else { tail->next=curr; }
        tail=curr;
        tail->next=NULL;
    }
    printf("A list has been created.\n");
}

void printList(){
    printf("The list now contains these numbers: ");
    for(curr=head;curr!=NULL;curr=curr->next){
        printf("%d, ", curr->num);
    }
    printf("\n");
}

 start();
 printList();

 map(square, linkedList);
 printList();
 system("PAUSE");   
 return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T23:39:49+00:00Added an answer on June 1, 2026 at 11:39 pm

    Defining all of those structs and functions inside of main is not how you’re supposed to write C. Move the int main(int argc, const char *argv[]) { to right after the definition of printList so that main only contains the actual code for main.

    Moreover, your definition of map appears to have an unfinished prototype. Instead of void map(int (*func)(int v), struct linkedList), in which the second parameter is unused, you want void map(int (*func)(int v), struct linkedList* head) (and then get rid of the declaration of head on the next line). Moreover, linkedList2 here presumably should be changed to linkedList. In addition, your attempt to call map in main with map(square, linkedList) is nonsensical; you want to use map(square, head).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my code (Say we have a single button on the page that
Here is my code, which takes two version identifiers in the form 1, 5,
Here is the code: Function getData(ByVal id As String) Dim reader As SqlClient.SqlDataReader Dim
here is code: <script type=text/javascript> function doit(){ $('table td').each(function () { if ($(this).text().trim() !=
Here's the deal: I'm in the process of planning a mid-sized business application that
Here is some simple code: DIR* pd = opendir(xxxx); struct dirent *cur; while (cur
Here's the code in AlertTableView: - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ NSInteger index = 12345; NSLog(@AlertTableView:
Here's my procedure: DROP PROCEDURE IF EXISTS `couponExpires`$$ CREATE DEFINER=`root`@`localhost` PROCEDURE `couponExpires`(IN couponID BIGINT,
Here is my problem : I have a post controller with the action create.
Here is an example. foreach (var doc in documents) { var processor = this.factory.Create();

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.