Skip to content

Instantly share code, notes, and snippets.

@chintanparikh
Created November 5, 2012 19:18
Show Gist options
  • Select an option

  • Save chintanparikh/4019724 to your computer and use it in GitHub Desktop.

Select an option

Save chintanparikh/4019724 to your computer and use it in GitHub Desktop.
3.c
#include <stdio.h>
#include <stdlib.h>
struct node {
int data;
struct *node next;
};
void push(struct node** headRef, int data)
{
struct node* newNode;
newNode = malloc(sizeof(struct node));
newNode->data = data;
newNode->next = *headRef;
*headRef = newNode;
}
struct node* primeFactors(int num)
{
struct node* head = NULL;
if (num == 1)
{
return head;
}
int factor = 0;
int i = 2;
while (i <= num)
{
if (num % i)
{
factor = i;
}
}
push(&head, factor);
primeFactors(num / factor);
return head;
}
int main(int argc, char const *argv[])
{
struct node* head = primeFactor(600851475143);
printf("%d/n", head->data);
}
[1] $ gcc 3.c -o 3
3.c:6:9: error: expected ‘{’ before ‘*’ token
3.c: In function ‘push’:
3.c:14:9: error: ‘struct node’ has no member named ‘next’
3.c: In function ‘main’:
3.c:42:22: warning: initialisation makes pointer from integer without a cast [enabled by default]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment