473,383 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

type of argument in printf function

5
I am trying to use swaps function and to initiate steps for a bubble sort. In the line 17 I tried to write `printf("%d", &nombre);`. and `printf("%d", nombre);` which respectively leed to the following warning, pasted after the snippet.


I cannot understand how to write the argument in the printf function. Can someone help me?






Expand|Select|Wrap|Line Numbers
  1.   #include <stdio.h>
  2.  2 void swaps(int *a, int *b);
  3.  3
  4.  4 int main()
  5.  5
  6.  6 {
  7.  7   int card, i, j;
  8.  8
  9.  9   printf("combien?\n");
  10. 10   scanf("%d", &card);
  11. 11   int nombre[card];
  12. 12   for (int i=0; i< card; i++)
  13. 13   {
  14. 14
  15. 15     printf("inscrivez un nombre.>
  16. 16     scanf("%d", &nombre[i]);} 
  17. 17     printf("%d", &nombre);
  18. 18     int fois = card/2;
  19. 19     while(fois <=0)
  20. 20    {
  21. 21      for(int i = 0; i < card-1; i++)
  22. 22      {
  23. 23       swaps(&nombre[i], &nombre[i+1]);
  24. 24      }
  25. 25    fois--;
  26. 26   }
  27. 27
  28. 28 for(int i = 0; i< sizeof(nombre)>
  29. 29   {
  30. 30      printf("%d", nombre[i]);
  31. 31   }
  32. 32 return 0;
  33. 33 }
  34. 34
  35. 35 void swaps(int *a, int *b)
  36. 36 {
  37. 37   int temp;
  38. 38   if (*a > *b)
  39. 39   {
  40. 40     temp = *a;
  41. 41     *a = *b;
  42. 42     *b = temp;
  43. 43   }
  44. 44
  45. 45 }
  46.  
  47.  
  48.  







`bu.c:17:18: warning: format
specifies type 'int' but the
argument has type 'int *'
[-Wformat]
printf("%d", nombre);
~~ ^~~~~~
1 warning generated.
$ nano bu.c
$ clang bu.c -o bu
bu.c:17:18: warning: format
specifies type 'int' but the
argument has type 'int
(*)[card]' [-Wformat]
printf("%d", &nombre);
~~ ^~~~~~~
1 warning generated.`
Nov 12 '19 #1

✓ answered by dev7060

When an array is declared, the name is a pointer to the first element of the array. So, here 'nombre' is an int type pointer (int*). %d format specifier is used to display int type values, not for printing addresses (%p is used for that). Here both nombre and &nombre denote addresses, not some int type value.

2 1961
dev7060
636 Expert 512MB
When an array is declared, the name is a pointer to the first element of the array. So, here 'nombre' is an int type pointer (int*). %d format specifier is used to display int type values, not for printing addresses (%p is used for that). Here both nombre and &nombre denote addresses, not some int type value.
Nov 12 '19 #2
kouty
5
I reached it!

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. //Compiler version gcc  6.3.0
  5. int swaps(int *num1, int *num2);
  6. int main()
  7.   int card;
  8.   printf("How many elements?\n");
  9.   scanf("%d", &card);
  10.   printf("The length of the array will be %d\n", card);
  11.   int numbers[card];
  12.   int *num = NULL;
  13.   num = numbers;
  14.  
  15.     for (int i = 0; i<card; i++)
  16.     {
  17.       printf ("enter the %d indexed number\n", i);
  18.       scanf ("%d", num+i);
  19.       printf("\nThe list of numbers is ");
  20.     }
  21.     for(int j=0; j< card; j++)
  22.     printf("%d, ", *(num + j);
  23.  
  24.     for(int a = 0; a < card; a++)
  25.     {
  26.       for(int b = a+1; b < card; b++)
  27.        {
  28.          if *(num +a) > *(num +b))
  29.          swaps(num+a, num+b);
  30.        }
  31.     }
  32.     printf("\nThe new list of numbers is ");
  33.     for(int j=0; j< card; j++)
  34.     printf("%d, ", *(num+j));
  35.  
  36.  
  37.   return 0;
  38. }
  39.  
  40. int swaps(int *num1, int *num2)
  41. {
  42.   int temp;
  43.   temp = *num1;
  44.   *num1 = *num2;
  45.   *num2 = temp;
  46. }
  47.  
Nov 14 '19 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: CoolPint | last post by:
As a self-exercise, I am trying to write a generic Priority Queue, which would store any type and and accept any user-definable "priority" function. After much tinkering, I came up with...
4
by: aling | last post by:
What's the rule of default argument of function in C++? I found that the default argument of function could not necessary be a constant value. Is it true? Previously I thought that the default...
2
by: rejeesh | last post by:
Hi, I need a 'wrapper' function for printf. So that anywhere in my program if i call the wrapper function it does the same thing as the regular printf function, but puts a custom message at the...
7
by: sunfiresg | last post by:
During an interview, I am asked to answer a question: Printf is a major formatted output function provided by the standard C library. Printf accepts a formatting string followed by a various...
1
by: tsarevich | last post by:
create type my_type (my_test text, my_int integer); create function my_function(my_type) returns timestamp as 'begin return (current_timestamp); end; ' language 'plpgsql';
18
by: sam_cit | last post by:
Hi Everyone, int main() { printf("not included stdio.h"); } Yes, i haven't included stdio.h and my compiler would generate a warning and would assume that it would return a int, my question...
19
by: sam_cit | last post by:
Hi Everyone, I have the following custom printf() function in the my program unit and when i execute the program, the actual printf() function is invoked and i get no error, no warning. However...
5
by: Sheldon | last post by:
Hi Everyone, I have defined a function: struct Transient arrFromHdfNode(HL_NodeList *nodelist, struct Transient retv); and in the code: struct Transient arrFromHdfNode(HL_NodeList...
7
by: mirandacascade | last post by:
The questions are toward the bottom of this post. Situation is this: 1) Access 97 2) Multi-user appplication 3) SQL Server 2000 4) Sporadically (i.e. less than 1% of the time) encounter the...
1
by: adimustdie | last post by:
char *chktype(char *Buffer, int Size)//checks the Content-Type and gives extension { unsigned short iphdrlen; struct iphdr *iph = (struct iphdr *)( Buffer + sizeof(struct ethhdr)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.