Can't figure out why num variable wont work

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

using namespace std;

int main()
{
int num,i,j,k,smallindex;
cout<<"Enter the number for which you want to enter the names"<<endl;
scanf("%d",&num);
char lastname[num][25];
char firstname[num][25];
char name[num][50];
for(i=0;i<num;i++)
{
cout<<"Enter the last name followed by first name separated by a comma"<<endl;
scanf("%s",name[i]);
j=0;
k=0;
while(name[i][j]!=',')
{
lastname[i][j]=name[i][j];
j++;
}
j++;
while(name[i][j]!='\0')
{
firstname[i][k++]=name[i][j];
j++;
}
}
for(i=0;i<num;i++)
{
for(j=i+1;j<num;j++)
{
if(strcmp(firstname[j],firstname[i])<0)
{
smallindex=j;
}
else
{
if(strcmp(firstname[j],firstname[i])==0)
{
if(strcmp(lastname[j],lastname[i])<0)
smallindex=j;
}
}
}
swap(name[i],name[smallindex]);
}
return 0;

}
int swap (char a[],char b[])
{
char temp[50];
strcpy(temp,b);
strcpy(b,a);
strcpy(a,temp);
}
Topic archived. No new replies allowed.