hi i am new to c/c++

i am making a program for a project in class

i have only started the program it still has no content, only structures however when i compiled and run it in C

the first printf wont display in the .exe

there are no errors

here is the code:

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

typedef double mNum[10];
typedef int *mDim;

//structure for dimension
typedef struct{
       mNum **pX;//declares double pointer for matrix
       mDim m,n; //variable size of matrix
}structDimension;

//structure for run-time initialization of matrix
mNum *initializeMatrix(structDimension n){
     mNum **temp;
     int ctr;
     for(ctr=0 ; ctr<n ; ctr++)
{
          temp[ctr]=malloc(sizeof(int)*n);
}
     return temp[ctr];
}


int main (int args, char *argv[]){
    structDimension *pX, m, n;
    int ctr; //counter - initializing memory location
    int ctrrow, ctrcol;//counter for clearing matrix and displaying values
    int ans;
    
    m=1;
    n=1;
    for(ctrrow=0 ; ctrrow<m ; ctrrow++){
          for(ctrcol=0 ; ctrcol<n ; ctrcol++){
                       pX[ctrrow][ctrcol] = 0;
          }
    }
    printf("\n\nGood Day!\n\n");
        
getch ();
free(pX);    
    
}

i tried compiling it in .cpp and i got these errors:

....cpp: In function `double (* initializeMatrix(structDimension))[10]':
....cpp:18: error: no match for 'operator<' in 'ctr < n'

....cpp:20: error: no match for 'operator*' in '4u * n'
....cpp: In function `int main(int, char**)':
....cpp:32: error: no match for 'operator=' in 'm = 1'
....cpp:9: note: candidates are: structDimension& structDimension::operator=(const structDimension&)
....cpp:33: error: no match for 'operator=' in 'n = 1'
....cpp:9: note: candidates are: structDimension& structDimension::operator=(const structDimension&)
....cpp:34: error: no match for 'operator<' in 'ctrrow < m'

....cpp:35: error: no match for 'operator<' in 'ctrcol < n'
....cpp:36: error: no match for 'operator[]' in '*((+(((unsigned int)ctrrow) * 12u)) + pX)[ctrcol]'

i am using bloodshed, and the automatic file extension is always .cpp and whenever i have problems using C, i save it in .cpp and it would work. however this is the first time i encountered problems with "no match for operator"


PLEASE HELP

Recommended Answers

All 2 Replies

When there are compiler errors, you get no .exe. You need to fix the errors before the program will be created; once an .exe is build you can run it.

You're trying to compare an int to a structure:

//structure for dimension
typedef struct{
       mNum **pX;//declares double pointer for matrix
       mDim m,n; //variable size of matrix
}structDimension;

//structure for run-time initialization of matrix
mNum *initializeMatrix(structDimension n){
     mNum **temp;
     int ctr;
     for(ctr=0 ; ctr<n ; ctr++)

Color the compiler confused.

here's my new code:

i still get errors, please help me correct them..
i am not very familiar with correcting errors,, need help
i am getting confused with the structures [it is required to use structures for this project]

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
 
typedef double mNum[10];
typedef int *mDim;
 
//structure for dimension
typedef struct{
       mNum **pX;//declares double pointer for matrix
       mDim m,n; //variable size of matrix
}structDimension;
 
//structure for run-time initialization of matrix
mNum **initializeMatrix(structDimension size){
     mNum **temp;
     int ctr;
     for(ctr=0 ; ctr<size.n[ctr] ; ctr++)
{
          temp[ctr] = malloc(sizeof(mNum)*size.n[ctr]);
}
     return temp;
}
mDim *initializeRC(){
     mDim *a, *b;
     int ctr;
     a[ctr] = malloc(sizeof(mDim) * 10);
     b[ctr] = malloc(sizeof(mDim) * 10);
}
 
int main (int args, char *argv[]){
   structDimension **matrix, row, col;
    int ctr; //counter - initializing memory location
    int *ctrrow, *ctrcol;//counter for clearing matrix and displaying values
    int ans; 
 
    row.m[ctr] = 1;
    col.n[ctr] = 1;
    for(ctrrow=0 ; ctrrow<row.m ; ctrrow++){
          for(ctrcol=0 ; ctrcol<col.n ; ctrcol++){
                       matrix[ctr][ctrrow][ctrcol] = 0;
          }
    }
    printf("\n\nGood Day!\n\n");
    printf("HELLO!");
 
free(matrix);  
return 0;
getch ();
 
}

....cpp: In function `double (** initializeMatrix(structDimension))[10]':
....cpp:20: error: invalid conversion from `void*' to `double (*)[10]'

....cpp: In function `int** initializeRC()':
....cpp:27: error: invalid conversion from `void*' to `int*'
....cpp:28: error: invalid conversion from `void*' to `int*'
....cpp: In function `int main(int, char**)':
....cpp:41: error: invalid types `structDimension*[int*]' for array subscript

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.