-1

I’m trying to make a program in C, having a matrix and find if a number in a position is there, but I get the following errors:

[solved]

funcao.c:8:2: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
  for(i=0; i=y; y++){
  ^
funcao.c:9:3: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   for(j=0;j=k; k++){
   ^
funcao.c:10:4: error: stray ‘\342’ in program
    if(∗(∗(m+i)+j)==numero){
    ^
funcao.c:10:4: error: stray ‘\210’ in program
funcao.c:10:4: error: stray ‘\227’ in program
funcao.c:10:4: error: stray ‘\342’ in program
funcao.c:10:4: error: stray ‘\210’ in program
funcao.c:10:4: error: stray ‘\227’ in program
funcao.c:10:22: warning: comparison between pointer and integer [enabled by default]
    if(∗(∗(m+i)+j)==numero){
                      ^
make: *** [funcao.o] Error 1

And my code is this:

int find_matriz(int **m, int number, int y, int k) {
    int find = 0;
    int i, j;
    for(i=0; i<y; y++) {
        for(j=0; j<k; k++) {
            if(*(*(m+i) + j) == number) {
                find = 1;
            }
        }
    }
    return find;
}

I couldn't find anything on the web or here about matrix and this errors. How can I fix this?

[not solved]

I keep getting an error after I change the code:

make: *** [run] Segmentation fault

Main code:

int main(void) {

    int m[5][2] = {{5,2}, {2,1}, {4,7}, {6,7}, {43,98}};
    int y = 2;
    int k = 1;
    int number = 2;

    int find = find_matriz(m, number, y, k);
    printf("find %d\n", find);

    return 0;
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • A direct analysis is: 342 210 227 (octal) → 0xE2 0x88 0x97 (hexadecimal) → UTF-8 sequence for Unicode code point U+2217 ([ASTERISK OPERATOR](https://www.utf8-chartable.de/unicode-utf8-table.pl?start=8704&number=128)). It can be searched for by regular expression `\x{2217}` (the notation is different in Visual Studio Code (and probably others): `\u2217`). – Peter Mortensen Apr 28 '23 at 22:35
  • 1
    This is a ***very*** common error when copying code from web pages, [PDF](https://en.wikipedia.org/wiki/Portable_Document_Format) documents, through chat (e.g. [Skype Chat](https://en.wikipedia.org/wiki/Features_of_Skype#Skype_chat) or [Facebook Messenger](https://en.wikipedia.org/wiki/Facebook_Messenger)), etc. The canonical question is *[Compilation error: stray ‘\302’ in program, etc.](https://stackoverflow.com/questions/19198332)*. – Peter Mortensen Apr 28 '23 at 22:37
  • Related: *[Exit strategies for "chameleon questions"](https://meta.stackexchange.com/questions/43478/exit-strategies-for-chameleon-questions)* – Peter Mortensen Apr 28 '23 at 22:41
  • This ought to have been ***two questions***, one for the stray error and one for the problem with the matrix code. They are two completely different problems. – Peter Mortensen Apr 28 '23 at 22:42

2 Answers2

1

The two stars in your if condition are not ordinary asterisks, but another character that looks similar. If you look closely, they look a bit different from the ones in the parameter list.

Thomas Padron-McCarthy
  • 27,232
  • 8
  • 51
  • 75
0

Consider:

for(i=0; i=y; y++) {
    for(j=0; j=k; k++) {

See these bot h loops and their conditions i=y and j=k. You assign them values for which the warning is about.

Probably do this:

for(i=0; i<y; i++) {
    for(j=0; j<k; j++) {

And this:

if(∗(∗(m+i) + j) == number) {

These are not the operators which are used to dereference a pointer.

Use * for dereferencing:

if(*(*(m+i) + j) == number) {   // Or simply write m[i][j]
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
ameyCU
  • 16,489
  • 2
  • 26
  • 41